| 1 | ' =========================================================
|
|---|
| 2 | ' WMI script to return the charge remaining in a laptop battery, using the
|
|---|
| 3 | ' EstimatedChargeRemaining property of the Win32_Battery class
|
|---|
| 4 | ' =========================================================
|
|---|
| 5 |
|
|---|
| 6 | ' Required Variables
|
|---|
| 7 | Const PROGNAME = "check_battery"
|
|---|
| 8 | Const VERSION = "0.0.1"
|
|---|
| 9 |
|
|---|
| 10 | ' Default settings for your script.
|
|---|
| 11 | threshold_warning = "50:"
|
|---|
| 12 | threshold_critical = "20:"
|
|---|
| 13 | strComputer = "."
|
|---|
| 14 |
|
|---|
| 15 | ' Create the NagiosPlugin object
|
|---|
| 16 | Set np = New NagiosPlugin
|
|---|
| 17 |
|
|---|
| 18 | ' Define what args that should be used
|
|---|
| 19 | np.add_arg "computer", "Computer name", 0
|
|---|
| 20 | np.add_arg "warning", "warning threshold", 0
|
|---|
| 21 | np.add_arg "critical", "critical threshold", 0
|
|---|
| 22 |
|
|---|
| 23 | ' If we have no args or arglist contains /help or not all of the required arguments are fulfilled show the usage output,.
|
|---|
| 24 | If Args.Exists("help") Then
|
|---|
| 25 | np.Usage
|
|---|
| 26 | End If
|
|---|
| 27 |
|
|---|
| 28 | ' If we define /warning /critical on commandline it should override the script default.
|
|---|
| 29 | If Args.Exists("warning") Then threshold_warning = Args("warning")
|
|---|
| 30 | If Args.Exists("critical") Then threshold_critical = Args("critical")
|
|---|
| 31 | If Args.Exists("computer") Then strComputer = Args("computer")
|
|---|
| 32 | np.set_thresholds threshold_warning, threshold_critical
|
|---|
| 33 |
|
|---|
| 34 | Set colInstances = np.simple_WMI_CIMV2(strComputer, "SELECT * FROM Win32_Battery")
|
|---|
| 35 | return_code = OK
|
|---|
| 36 |
|
|---|
| 37 | For Each objInstance In colInstances
|
|---|
| 38 | if message <> "" then : message = message & ", "
|
|---|
| 39 | if perf <> "" then : perf = perf & ", "
|
|---|
| 40 | message = message & "Battery " & objInstance.Status & " - Charge Remaining = " & objInstance.EstimatedChargeRemaining & "%"
|
|---|
| 41 | perf = perf & "charge=" & objInstance.EstimatedChargeRemaining
|
|---|
| 42 | return_code = np.escalate_check_threshold(return_code, objInstance.EstimatedChargeRemaining)
|
|---|
| 43 | Next
|
|---|
| 44 | ' Nice Exit with msg and exitcode
|
|---|
| 45 | np.nagios_exit message & "|" & perf, return_code
|
|---|