Registry key value check
Posted: Wed Dec 18, 2019 10:44 am
Hello Nagios Support
Do you have any operational script (PS or VBS) to check for Windows registry values?
Here is one we've tried to adopt from NAGIOS Exchange but no luck so far (it is the script itself whihc can't read the registry key, unsure why)
----
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' NAGIOS and NSClient++ CONFIGURATION:
'
' ### command definition ###
'
' define command {
' command_name check_mscs
' command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c $ARG1$"
' }
'
'
' ### service definition ###
'
' define service{
' use generic-service
' host_name MyServer
' service_description Registry_Logons_Enabled
' process_perf_data 0
' check_command check_nrpe!check_reg_key -a "HKEY_LOCAL_MACHINE" "\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\RCM\\Licensing Core" "LicensingMode" "4"
' }
'
'
' ### command line ###
'
' ./check_nrpe -H $HOSTADDRESS$ -p 5666 -c check_reg_key -a "HKEY_LOCAL_MACHINE" "\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\RCM\\Licensing Core" "LicensingMode" "4"
'
'
' ### NSC.ini configuration ###
'
' CheckExternalScripts.dll
'
' [External Script]
' allow_arguments=1
' allow_nasty_meta_chars=1
'
' [External Scripts]
' check_reg_key=cscript.exe //T:30 //Nologo scripts\check_reg_key.vbs "$ARG1$" "ARG2$" "$ARG3$" "$ARG4$"
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option explicit
Dim strHive, strKeyPath, strValueName, strExpectedValue
Dim strComputer, strValue, oReg, strHiveKey
'RC to NAGIOS
Const intOK = 4
Const intWarning = 2
Const intCritical = 5
Const intUnknown = 0
strComputer = "."
' Check for arguments
'WScript.Echo WScript.Arguments.Count
If WScript.Arguments.Count = 0 then
Display_Usage()
If WScript.Arguments.Count < 4 Then
WScript.Echo "not enough arguments supplied."
Display_Usage()
ElseIf WScript.Arguments.Count > 4 Then
WScript.Echo "too many arguments supplied."
Display_Usage()
End if
End If
strHive = UCase(WScript.Arguments.Item(0))
' WScript.Echo "strHive = " & strHive
strKeyPath = WScript.Arguments.Item(1)
' WScript.Echo "strKeyPath = " & strKeyPath
strValueName = WScript.Arguments.Item(2)
' WScript.Echo "strValueName = " & strValueName
strExpectedValue = WScript.Arguments.Item(3)
' WScript.Echo "strExpectedValue = " & strExpectedValue
strHiveKey = strHive
Select Case strHive
Case "HKEY_LOCAL_MACHINE"
strHive = &H80000002
Case "HKEY_CURRENT_USER"
strHive = &H80000001
Case "HKEY_USERS"
strHive = &H80000003
Case Else
WScript.Echo "Unrecognised Registry Hive Key - " & strHive
WScript.Quit(intUnknown)
End Select
WScript.Echo strHiveKey,strKeyPath,strValueName,strExpectedValue
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
oReg.GetStringValue strHive,strKeyPath,strValueName,strValue
If IsNull(strValue) Then
WScript.Echo "Registry Key not found"
WScript.Quit(intWarning)
End If
Select Case LCase(strValue)
Case LCase(strExpectedValue)
WScript.Echo "Expected Value (" & strExpectedValue & ") Matches: " & strValue
WScript.Quit(intOK)
Case Else
WScript.Echo "Expected Value (" & strExpectedValue & ") does not match: " & strValue
WScript.Quit(intCritical)
End Select
Function Display_Usage
Wscript.StdOut.WriteLine "Check RDS Licensing Registry Key"
Wscript.StdOut.WriteLine "----------------------------------------------------------------"
Wscript.StdOut.WriteLine "Usage: cscript.exe check_reg_key.vbs 'REGISTRY_HIVE' 'KEY_PATH' 'VALUE_NAME' 'EXPECTED_VALUE'" & vbcrlf
Wscript.StdOut.WriteLine "Examples: "
Wscript.StdOut.WriteLine "cscript.exe check_reg_key.vbs HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\RCM\Licensing Core" & vbcrlf
Wscript.StdOut.WriteLine " REGISTRY_HIVE = HKEY_LOCAL_MACHINE"
Wscript.StdOut.WriteLine " KEY_PATH = SYSTEM\CurrentControlSet\Control\Terminal Server\RCM\Licensing Core"
Wscript.StdOut.WriteLine " VALUE_NAME = LicensingMode"
WScript.Quit(intOK)
End Function
----
Do you have any operational script (PS or VBS) to check for Windows registry values?
Here is one we've tried to adopt from NAGIOS Exchange but no luck so far (it is the script itself whihc can't read the registry key, unsure why)
----
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' NAGIOS and NSClient++ CONFIGURATION:
'
' ### command definition ###
'
' define command {
' command_name check_mscs
' command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c $ARG1$"
' }
'
'
' ### service definition ###
'
' define service{
' use generic-service
' host_name MyServer
' service_description Registry_Logons_Enabled
' process_perf_data 0
' check_command check_nrpe!check_reg_key -a "HKEY_LOCAL_MACHINE" "\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\RCM\\Licensing Core" "LicensingMode" "4"
' }
'
'
' ### command line ###
'
' ./check_nrpe -H $HOSTADDRESS$ -p 5666 -c check_reg_key -a "HKEY_LOCAL_MACHINE" "\\SYSTEM\\CurrentControlSet\\Control\\Terminal Server\\RCM\\Licensing Core" "LicensingMode" "4"
'
'
' ### NSC.ini configuration ###
'
' CheckExternalScripts.dll
'
' [External Script]
' allow_arguments=1
' allow_nasty_meta_chars=1
'
' [External Scripts]
' check_reg_key=cscript.exe //T:30 //Nologo scripts\check_reg_key.vbs "$ARG1$" "ARG2$" "$ARG3$" "$ARG4$"
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Option explicit
Dim strHive, strKeyPath, strValueName, strExpectedValue
Dim strComputer, strValue, oReg, strHiveKey
'RC to NAGIOS
Const intOK = 4
Const intWarning = 2
Const intCritical = 5
Const intUnknown = 0
strComputer = "."
' Check for arguments
'WScript.Echo WScript.Arguments.Count
If WScript.Arguments.Count = 0 then
Display_Usage()
If WScript.Arguments.Count < 4 Then
WScript.Echo "not enough arguments supplied."
Display_Usage()
ElseIf WScript.Arguments.Count > 4 Then
WScript.Echo "too many arguments supplied."
Display_Usage()
End if
End If
strHive = UCase(WScript.Arguments.Item(0))
' WScript.Echo "strHive = " & strHive
strKeyPath = WScript.Arguments.Item(1)
' WScript.Echo "strKeyPath = " & strKeyPath
strValueName = WScript.Arguments.Item(2)
' WScript.Echo "strValueName = " & strValueName
strExpectedValue = WScript.Arguments.Item(3)
' WScript.Echo "strExpectedValue = " & strExpectedValue
strHiveKey = strHive
Select Case strHive
Case "HKEY_LOCAL_MACHINE"
strHive = &H80000002
Case "HKEY_CURRENT_USER"
strHive = &H80000001
Case "HKEY_USERS"
strHive = &H80000003
Case Else
WScript.Echo "Unrecognised Registry Hive Key - " & strHive
WScript.Quit(intUnknown)
End Select
WScript.Echo strHiveKey,strKeyPath,strValueName,strExpectedValue
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _
strComputer & "\root\default:StdRegProv")
oReg.GetStringValue strHive,strKeyPath,strValueName,strValue
If IsNull(strValue) Then
WScript.Echo "Registry Key not found"
WScript.Quit(intWarning)
End If
Select Case LCase(strValue)
Case LCase(strExpectedValue)
WScript.Echo "Expected Value (" & strExpectedValue & ") Matches: " & strValue
WScript.Quit(intOK)
Case Else
WScript.Echo "Expected Value (" & strExpectedValue & ") does not match: " & strValue
WScript.Quit(intCritical)
End Select
Function Display_Usage
Wscript.StdOut.WriteLine "Check RDS Licensing Registry Key"
Wscript.StdOut.WriteLine "----------------------------------------------------------------"
Wscript.StdOut.WriteLine "Usage: cscript.exe check_reg_key.vbs 'REGISTRY_HIVE' 'KEY_PATH' 'VALUE_NAME' 'EXPECTED_VALUE'" & vbcrlf
Wscript.StdOut.WriteLine "Examples: "
Wscript.StdOut.WriteLine "cscript.exe check_reg_key.vbs HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server\RCM\Licensing Core" & vbcrlf
Wscript.StdOut.WriteLine " REGISTRY_HIVE = HKEY_LOCAL_MACHINE"
Wscript.StdOut.WriteLine " KEY_PATH = SYSTEM\CurrentControlSet\Control\Terminal Server\RCM\Licensing Core"
Wscript.StdOut.WriteLine " VALUE_NAME = LicensingMode"
WScript.Quit(intOK)
End Function
----