File: 1.00.3a/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.02" 51: OB "
"
52: 53: 54: 55: 56: 57: 58: Function OB(text) 59: OutputBuffer = OutputBuffer & text & vbCrLf 60: End Function 61: 62: Function DumpOB() 63: Wscript.Echo OutputBuffer 64: End Function 65: 66: strComputer = "." 67: Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 68: 69: 70: set objRefresher = CreateObject("WbemScripting.Swbemrefresher") 71: Set objProcessor = objRefresher.AddEnum (objWMIService, "Win32_PerfFormattedData_PerfOS_Processor").objectSet 72: 73: Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service") 74: Set memItems = objRefresher.AddEnum (objWMIService, "Win32_PerfFormattedData_PerfOS_Memory").objectSet 75: Set colOperatingSystems = objWMIService.ExecQuery ("Select * from Win32_OperatingSystem") 76: 77: Set WshNetwork = WScript.CreateObject("WScript.Network") 78: AddTest "system.name","Computer Name",WshNetwork.ComputerName,0 79: 80: 81: objRefresher.Refresh ' No I don't really get it either 82: WScript.Sleep 2000 ' but unless you do this you get even 83: objRefresher.Refresh ' weirder than usual values. 84: 85: int ServiceRunning=0 86: int Alert=0 87: For Each objService in colRunningServices 88: If objService.State = "Running" Then 89: ServiceRunning=1 90: Alert=0 91: Else 92: Alert=1 93: ServiceRunning=0 94: End If 95: TestName="srv." & Replace(objService.Name," ","_") 96: AddTest TestName, Replace(objService.DisplayName,"&","+") & " Service", ServiceRunning, Alert 97: Next 98: 99: 100: intThresholdViolations = 0 101: 102: 103: Set colDisks = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk") 104: For Each objDisk in colDisks 105: DiskSpace = objDisk.FreeSpace / 1024 / 1024 106: If DiskSpace = "" Then 107: DiskSpace = "0" 108: End If 109: TestName= "disk.free." & Left(objDisk.DeviceID,1) 110: AddTest TestName,"Space Free On " & objDisk.DeviceID & " (Mb)", DiskSpace, 0 111: 112: Next 113: 114: 115: For Each objItem in objProcessor 116: 117: If objItem.Name = "_Total" Then 118: AddTest "proc.load","Processor Load (%)",objItem.PercentProcessorTime,0 119: End If 120: Next 121: 122: 123: 124: For Each objOS in colOperatingSystems 125: dtmBootup = objOS.LastBootUpTime 126: dtmLastBootupTime = WMIDateStringToDate(dtmBootup) 127: dtmSystemUptime = DateDiff("h", dtmLastBootUpTime, Now) 128: AddTest "uptime","Uptime (Hours)",dtmSystemUptime,0 129: Next 130: 131: Function WMIDateStringToDate(dtmBootup) 132: WMIDateStringToDate = CDate(Mid(dtmBootup, 5, 2) & "/" & _ 133: Mid(dtmBootup, 7, 2) & "/" & Left(dtmBootup, 4) _ 134: & " " & Mid (dtmBootup, 9, 2) & ":" & _ 135: Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2)) 136: End Function 137: 138: 139: 140: 141: For Each objItem in memItems 142: TestName="mem." 143: If Len(objItem.Name) > 0 Then 144: TestName = TestName & objItem.Name & "." 145: End If 146: TestName = TestName & "free" 147: 148: AddTest TestName,"Memory Available (Kilobytes)",objItem.AvailableKBytes,0 149: 150: Next 151: 152: 153: OB "" 154: 155: Function AddTest(testname,testdesc,testvalue,alertlevel) 156: OB "" 157: OB " " & testname & "" 158: OB " " & testdesc & "" 159: OB " " & testvalue & "" 160: OB " " & alertlevel & "" 161: OB "" 162: End Function 163: 164: If PullData=1 Then 165: DumpOB() 166: End If 167: 168: If PushData=1 Then 169: ' Push Da Data 170: WScript.Echo 171: WScript.Echo "Pushing Data..." 172: WScript.Echo "URL : " & PushURL 173: WScript.Echo "NodeID: " & NodeID 174: WScript.Echo "Key : " & NodeKey 175: 176: Set objHTTP = CreateObject("Microsoft.XMLHTTP") 177: objHTTP.open "POST", PushURL, False 178: 179: objHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded" 180: http_request = "nodeid=" & Escape(NodeID) & "&nodekey=" & Escape(NodeKey) & "&xml=" & Escape(OutputBuffer) 181: objHTTP.send http_request 182: 183: response = objHTTP.responseText 184: 185: Set objHTTP = Nothing 186: 187: If Right(response,1) = "1" Then 188: WScript.Echo "Post Successful" 189: Else 190: WScript.Echo "Encountered An Error:" 191: WScript.Echo response 192: End If 193: 194: End If