#wip(vbs): VBS building...
This commit is contained in:
parent
c178dbd9b2
commit
36e6187c04
3
JSON/I18N/NucelarMonitor.i18n.english.json
Normal file
3
JSON/I18N/NucelarMonitor.i18n.english.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"english" : {}
|
||||
}
|
||||
3
JSON/I18N/NucelarMonitor.i18n.espanol.json
Normal file
3
JSON/I18N/NucelarMonitor.i18n.espanol.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"espanol" : {}
|
||||
}
|
||||
3
JSON/I18N/NucelarMonitor.i18n.galego.json
Normal file
3
JSON/I18N/NucelarMonitor.i18n.galego.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"galego" : {}
|
||||
}
|
||||
1
JSON/NucelarMonitor.settings.json
Normal file
1
JSON/NucelarMonitor.settings.json
Normal file
@ -0,0 +1 @@
|
||||
{}
|
||||
6
Tools/NucelarMonitor.bat
Normal file
6
Tools/NucelarMonitor.bat
Normal file
@ -0,0 +1,6 @@
|
||||
@echo off
|
||||
|
||||
:bucle
|
||||
cscript //nologo ..\VisualBasicScripts\NucelarMonitor.vbs
|
||||
@ping 127.255.255.255 -n 1 -w 5000 >nul
|
||||
goto bucle
|
||||
139
VisualBasicScripts/NucelarMonitor.vbs
Normal file
139
VisualBasicScripts/NucelarMonitor.vbs
Normal file
@ -0,0 +1,139 @@
|
||||
Option Explicit
|
||||
On Error Resume Next
|
||||
|
||||
Dim url_target, hostnames, domain, wmi_service, ips, item, disks_info, key, http, total_size, free_size, json
|
||||
Dim print_json, send_data
|
||||
Dim interval_milliseconds, captures_milliseconds, value, iterations, items, i, start_date
|
||||
Dim cpu_maximum, cpu_minimum, cpu_average, cpu_in, cpu_out, cpu_summatory
|
||||
Dim memory_maximum, memory_minimum, memory_average, memory_in, memory_out, memory_summatory, total_memory
|
||||
|
||||
key = "pc_miguel"
|
||||
print_json = True
|
||||
send_data = False
|
||||
url_target = ""
|
||||
ips = ""
|
||||
disks_info = ""
|
||||
start_date = DateDiff("s", #1/1/1970#, Now)
|
||||
interval_milliseconds = 10000
|
||||
captures_milliseconds = 10
|
||||
iterations = 0
|
||||
cpu_summatory = 0
|
||||
cpu_in = -1
|
||||
cpu_minimum = 100
|
||||
cpu_maximum = 0
|
||||
cpu_average = 0
|
||||
total_memory = -1
|
||||
memory_summatory = 0
|
||||
memory_average = 0
|
||||
|
||||
Set wmi_service = GetObject("winmgmts:\\.\root\cimv2")
|
||||
|
||||
For Each item In wmi_service.ExecQuery("SELECT Name, Domain FROM Win32_ComputerSystem")
|
||||
If domain = "" Then domain = item.Domain End If
|
||||
If hostnames <> "" Then hostnames = hostnames & "," End If
|
||||
hostnames = hostnames & """" & item.Name & """"
|
||||
Next
|
||||
|
||||
For Each item In wmi_service.ExecQuery("SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = True")
|
||||
If Not IsNull(item.IPAddress) Then
|
||||
If ips <> "" Then ips = ips & "," End If
|
||||
ips = ips & """" & item.IPAddress(0) & """"
|
||||
End If
|
||||
Next
|
||||
|
||||
For Each item In wmi_service.ExecQuery("SELECT DeviceID, Size, FreeSpace FROM Win32_LogicalDisk where DriveType = 3")
|
||||
|
||||
If disks_info <> "" Then disks_info = disks_info & "," End If
|
||||
If IsNull(item.Size) Then total_size = 0 Else total_size = item.Size End If
|
||||
If IsNull(item.FreeSpace) Then free_size = 0 Else free_size = item.FreeSpace End If
|
||||
|
||||
disks_info = disks_info & "[""" & item.DeviceID & """," & total_size & "," & free_size & "]"
|
||||
|
||||
Next
|
||||
|
||||
While DateDiff("s", #1/1/1970#, Now) - start_date < (interval_milliseconds / 1000)
|
||||
On Error Resume Next
|
||||
|
||||
iterations = iterations + 1
|
||||
|
||||
For Each item In wmi_service.ExecQuery("Select LoadPercentage from Win32_Processor")
|
||||
|
||||
value = item.LoadPercentage
|
||||
|
||||
if cpu_in < 0 Then cpu_in = value End If
|
||||
if value < cpu_minimum Then cpu_minimum = value End If
|
||||
if value > cpu_maximum Then cpu_maximum = value End If
|
||||
cpu_summatory = cpu_summatory + value
|
||||
cpu_out = value
|
||||
|
||||
Next
|
||||
|
||||
For Each item In wmi_service.ExecQuery("Select FreePhysicalMemory, TotalVisibleMemorySize from Win32_OperatingSystem")
|
||||
|
||||
value = item.FreePhysicalMemory
|
||||
|
||||
if total_memory < 0 Then
|
||||
total_memory = item.TotalVisibleMemorySize
|
||||
memory_minimum = value
|
||||
memory_maximum = value
|
||||
memory_in = value
|
||||
Else
|
||||
if value < memory_minimum Then memory_minimum = value End If
|
||||
if value > memory_maximum Then memory_maximum = value End If
|
||||
End If
|
||||
memory_summatory = memory_summatory + value
|
||||
memory_out = value
|
||||
|
||||
Next
|
||||
|
||||
WScript.Sleep captures_milliseconds
|
||||
|
||||
If Err.Number <> 0 Then WScript.Echo "Error: " & Err.Number & " - " & Err.Description End If
|
||||
|
||||
Wend
|
||||
|
||||
' Para el futuro, los servicios.
|
||||
' SELECT Name, State FROM Win32_Service WHERE Name = 'Spooler'
|
||||
|
||||
if cpu_summatory <> 0 and iterations <> 0 Then cpu_average = Replace(CStr(cpu_summatory / iterations), ",", ".") End If
|
||||
If memory_summatory <> 0 and iterations <> 0 Then memory_average = Round(memory_summatory / iterations) End If
|
||||
|
||||
json = "["
|
||||
json = json & """" & key & ""","
|
||||
json = json & "[" & hostnames & "],""" & domain & """,[" & ips & "],[" & disks_info & "],"
|
||||
json = json & "[" & start_date & "," & DateDiff("s", #1/1/1970#, Now) & "],"
|
||||
json = json & iterations & ","
|
||||
json = json & "[" & cpu_in & "," & cpu_out & "," & cpu_minimum & "," & cpu_maximum & "," & cpu_average & "]"
|
||||
json = json & "[" & total_memory & "," & memory_in & "," & memory_out & "," & memory_minimum & "," & memory_maximum & "," & memory_average & "]"
|
||||
json = json & "]"
|
||||
|
||||
if print_json Then
|
||||
WScript.Echo json
|
||||
End If
|
||||
|
||||
If send_data Then
|
||||
|
||||
Err.Clear
|
||||
Set http = CreateObject("WinHttp.WinHttpRequest.5.1")
|
||||
|
||||
' Para retrocompatibilidad con Windows 2000 y XP.
|
||||
if Err.Number <> 0 Then
|
||||
Err.Clear
|
||||
set http = CreateObject("Microsoft.XMLHTTP")
|
||||
End If
|
||||
|
||||
If http is Nothing Then
|
||||
WScript.Echo "No se pudo crear el objeto HTTP."
|
||||
WScript.Quit 1
|
||||
ElseIf url_target <> "" Then
|
||||
http.Open "POST", url_target, False
|
||||
http.SetRequestHeader "Content-Type", "application/json"
|
||||
http.Send json
|
||||
Else
|
||||
WScript.Echo "URL de destino no especificada."
|
||||
End If
|
||||
|
||||
End If
|
||||
|
||||
Set http = Nothing
|
||||
Set wmi_service = Nothing
|
||||
Loading…
Reference in New Issue
Block a user