File:
1.00.2a/node/win32/node.vbs (
View as Code)
1: ' REM FreeNATS Windows Node Bogeroo
2: '
3: ' This file is part of FreeNATS
4: '
5: ' FreeNATS is (C) Copyright 2008 PurplePixie Systems
6: '
7: ' FreeNATS is free software: you can redistribute it and/or modify
8: ' it under the terms of the GNU General Public License as published by
9: ' the Free Software Foundation, either version 3 of the License, or
10: ' (at your option) any later version.
11: '
12: ' FreeNATS is distributed in the hope that it will be useful,
13: ' but WITHOUT ANY WARRANTY; without even the implied warranty of
14: ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: ' GNU General Public License for more details.
16: '
17: ' You should have received a copy of the GNU General Public License
18: ' along with FreeNATS. If not, see www.gnu.org/licenses
19: '
20: ' For more information see www.purplepixie.org/freenats
21:
22: PushData=0
23: PullData=1
24: PushURL=""
25: NodeID=""
26: NodeKey="" 'for post only
27:
28: Set colNamedArguments= WScript.Arguments.Named
29:
30: If colNamedArguments.Exists("nooutput") Then
31: PullData=0
32: End If
33: If colNamedArguments.Exists("pushurl") Then
34: PushData=1
35: PushURL=colNamedArguments.Item("pushurl")
36: End If
37: If colNamedArguments.Exists("nodeid") Then
38: NodeID=colNamedArguments.Item("nodeid")
39: End If
40: If colNamedArguments.Exists("nodekey") Then
41: NodeKey=colNamedArguments.Item("nodekey")
42: End If
43:
44: OutputBuffer = ""
45:
46: OB ""
47: OB ""
48: OB " 49: OB " FreeNATS VBS Node XML"
50: OB " 0.01"
51: OB " "
52:
53: Function Fred(x,y)
54: OB x
55: OB y
56: End Function
57:
58:
59:
60:
61: Function OB(text)
62: OutputBuffer = OutputBuffer & text & vbCrLf
63: End Function
64:
65: Function DumpOB()
66: Wscript.Echo OutputBuffer
67: End Function
68:
69: strComputer = "."
70: Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
71:
72:
73: set objRefresher = CreateObject("WbemScripting.Swbemrefresher")
74: Set objProcessor = objRefresher.AddEnum (objWMIService, "Win32_PerfFormattedData_PerfOS_Processor").objectSet
75:
76: Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")
77: Set memItems = objRefresher.AddEnum (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSet
78: Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem")
79:
80: Set WshNetwork = WScript.CreateObject("WScript.Network")
81: AddTest "system.name","Computer Name",WshNetwork.ComputerName,0
82:
83:
84: objRefresher.Refresh
85:
86: objRefresher.Refresh
87:
88: int ServiceRunning=0
89: int Alert=0
90: For Each objService in colRunningServices
91: If objService.State = "Running" Then
92: ServiceRunning=1
93: Alert=0
94: Else
95: Alert=1
96: ServiceRunning=0
97: End If
98: TestName="srv." & Replace(objService.Name," ","_")
99: AddTest TestName, Replace(objService.DisplayName,"&","+") & " Service", ServiceRunning, Alert
100: 'Fred 1,2
101: Next
102:
103:
104: intThresholdViolations = 0
105:
106:
107: Set colDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk")
108: For Each objDisk in colDisks
109: DiskSpace = objDisk.FreeSpace / 1024 / 1024
110: If DiskSpace = "" Then
111: DiskSpace = "0"
112: End If
113: TestName= "disk.free." & Left(objDisk.DeviceID,1)
114: AddTest TestName,"Space Free On " & objDisk.DeviceID & " (Mb)", DiskSpace, 0
115:
116: Next
117:
118:
119: For Each objItem in objProcessor
120:
121: If objItem.Name = "_Total" Then
122: AddTest "proc.load","Processor Load (%)",objItem.PercentProcessorTime,0
123: End If
124: Next
125:
126:
127:
128: For Each objOS in colOperatingSystems
129: dtmBootup = objOS.LastBootUpTime
130: dtmLastBootupTime = WMIDateStringToDate(dtmBootup)
131: dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now)
132: AddTest "uptime","Uptime (Hours)",dtmSystemUptime,0
133: Next
134:
135: Function WMIDateStringToDate(dtmBootup)
136: WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _
137: Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _
138: & " " & Mid (dtmBootup, 9, 2) & ":" & _
139: Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2))
140: End Function
141:
142:
143:
144:
145: For Each objItem in memItems
146: TestName="mem."
147: If Len(objItem.Name) > 0 Then
148: TestName = TestName & objItem.Name & "."
149: End If
150: TestName = TestName & "free"
151:
152: AddTest TestName,"Memory Available (Kilobytes)",objItem.AvailableKBytes,0
153:
154: Next
155:
156:
157: OB ""
158:
159: Function AddTest(testname,testdesc,testvalue,alertlevel)
160: OB ""
161: OB " " & testname & ""
162: OB " " & testdesc & ""
163: OB " " & testvalue & ""
164: OB " " & alertlevel & ""
165: OB ""
166: End Function
167:
168: If PullData=1 Then
169: DumpOB()
170: End If
171:
172: If PushData=1 Then
173: ' Push Da Data
174: WScript.Echo
175: WScript.Echo "Pushing Data..."
176: WScript.Echo "URL : " & PushURL
177: WScript.Echo "NodeID: " & NodeID
178: WScript.Echo "Key : " & NodeKey
179:
180: Set objHTTP = CreateObject("Microsoft.XMLHTTP")
181: objHTTP.open "POST", PushURL, False
182:
183: objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
184: http_request = "nodeid=" & Escape(NodeID) & "&nodekey=" & Escape(NodeKey) & "&xml=" & Escape(OutputBuffer)
185: objHTTP.send http_request
186:
187: response = objHTTP.responseText
188:
189: Set objHTTP = Nothing
190:
191: If Right(response,1) = "1" Then
192: WScript.Echo "Post Successful"
193: Else
194: WScript.Echo "Encountered An Error:"
195: WScript.Echo response
196: End If
197:
198: End If