From 1bb6dae8444d918438b5e18a31fdff5eee9981ee Mon Sep 17 00:00:00 2001 From: fermin831 Date: Thu, 23 Feb 2017 12:54:33 +0100 Subject: [PATCH] Added df_percent_used and mem_percent_used plugins --- .../win32/bin/util/df_percent_used.vbs | 49 ++++++++++++++++ .../win32/bin/util/mem_percent_used.vbs | 57 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 pandora_agents/win32/bin/util/df_percent_used.vbs create mode 100644 pandora_agents/win32/bin/util/mem_percent_used.vbs diff --git a/pandora_agents/win32/bin/util/df_percent_used.vbs b/pandora_agents/win32/bin/util/df_percent_used.vbs new file mode 100644 index 0000000000..49440b5e16 --- /dev/null +++ b/pandora_agents/win32/bin/util/df_percent_used.vbs @@ -0,0 +1,49 @@ +' df_all.vbs +' Returns used space (%) for all drives +' Pandora FMS Plugin, (c) 2014 Sancho Lerena +' ------------------------------------------ + +Option Explicit +On Error Resume Next + +' Variables +Dim objWMIService, objItem, colItems, argc, argv, i, Percent + + +' Parse command line parameters +argc = Wscript.Arguments.Count +Set argv = CreateObject("Scripting.Dictionary") +For i = 0 To argc - 1 + argv.Add Wscript.Arguments(i), i +Next + +' Get drive information +Set objWMIService = GetObject ("winmgmts:\\.\root\cimv2") +Set colItems = objWMIService.ExecQuery ("Select * from Win32_LogicalDisk") + +For Each objItem in colItems + If argc = 0 Or argv.Exists(objItem.Name) Then + ' Include only harddrivers (type 3) + If (objItem.FreeSpace <> "") AND (objItem.DriveType =3) Then + Percent = round (100 - (objItem.FreeSpace / objItem.Size) * 100, 2) + Wscript.StdOut.WriteLine "" + Wscript.StdOut.WriteLine " " + Wscript.StdOut.WriteLine " " + If (Percent > 99.99) then + Wscript.StdOut.WriteLine " " + Elseif (Percent < 0.01) then + Wscript.StdOut.WriteLine " " + Else + Wscript.StdOut.WriteLine " " + End If + Wscript.StdOut.WriteLine " %" + Wscript.StdOut.WriteLine " 90" + Wscript.StdOut.WriteLine " 0" + Wscript.StdOut.WriteLine " 95" + Wscript.StdOut.WriteLine " 0" + Wscript.StdOut.WriteLine " System" + Wscript.StdOut.WriteLine "" + Wscript.StdOut.flush + End If + End If +Next diff --git a/pandora_agents/win32/bin/util/mem_percent_used.vbs b/pandora_agents/win32/bin/util/mem_percent_used.vbs new file mode 100644 index 0000000000..15733b60f1 --- /dev/null +++ b/pandora_agents/win32/bin/util/mem_percent_used.vbs @@ -0,0 +1,57 @@ +' mem_percent_used.vbs +' Returns used RAM (%) +' Pandora FMS Plugin, (c) 2017 Fermin Hernandez +' ------------------------------------------ + +Dim usedMEM, totalMEM, Percent + +strComputer = "." +Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") + +Set colRAMs = objWMIService.ExecQuery("Select capacity from Win32_PhysicalMemory") +For Each total in colRAMs + totalMEM = total.capacity +Next + +Set colUSEDs = objWMIService.ExecQuery("Select freePhysicalMemory from Win32_OperatingSystem") +For Each used in colUSEDs + usedMEM = used.freePhysicalMemory * 1024 +Next + +on error resume next +flag = colRAMs.Count +If (err.number <> 0) Then + flag = true +Else + flag = false +End If +on error goto 0 + +on error resume next +flag = colUSEDs.Count +If (err.number <> 0) Then + flag = true +Else + flag = false +End If +on error goto 0 + +'Print only when there's results +If (NOT flag) Then + Percent = round (100 - (usedMEM / totalMEM) * 100, 2) + Wscript.StdOut.WriteLine "" + Wscript.StdOut.WriteLine " " + Wscript.StdOut.WriteLine " " + If (Percent > 99.99) then + Wscript.StdOut.WriteLine " " + Elseif (Percent < 0.01) then + Wscript.StdOut.WriteLine " " + Else + Wscript.StdOut.WriteLine " " + End If + Wscript.StdOut.WriteLine " %" + Wscript.StdOut.WriteLine " 95" + Wscript.StdOut.WriteLine " 100" + Wscript.StdOut.WriteLine " System" + Wscript.StdOut.WriteLine "" +End If