Powershell performance script - exchange monitoring script

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Tune
Posts: 15
Joined: Wed Nov 02, 2016 9:53 am

Powershell performance script - exchange monitoring script

Post by Tune »

I am trying to get an Exchange Nagios Plugin to work, and report back to Nagios.

I have succesfully installed NSCP-0.4.3-x64.msi, and rebooted the server, and The NSCP-0.4.3 Client is communicating succesfully with my Nagios XI 5.4.3 and I am attempting to get a third party powershell to work, and report back to my Nagios 5.4.3.

The plugin I am trying to use is
https://exchange.nagios.org/directory/P ... a)/details

My ini file is a mess, and I am spending days to trying figure out how I get it to work, hoppefully someone can correct my Ini file?

Code: Select all

; Undocumented section


[/settings/default]

; TIMEOUT - Timeout when reading packets on incoming sockets. If the data has not arrived within this time we will bail out.
timeout = 30

; CACHE ALLOWED HOSTS - If host names (DNS entries) should be cached, improves speed and security somewhat but won't allow you to have dynamic IPs for your Nagios server.
cache allowed hosts = true

; ALLOWED HOSTS - A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.
allowed hosts = 127.0.0.1,::1,10.10.10.148

; PASSWORD - Password used to authenticate against server
password = deletedfor4forum

; BIND TO ADDRESS - Allows you to bind server to a specific local address. This has to be a dotted ip address not a host name. Leaving this blank will bind to all available IP addresses.
bind to = 


; Undocumented section
[/settings/NRPE/server]

; EXTENDED RESPONSE - Send more then 1 return packet to allow response to go beyond payload size (requires modified client if legacy is true this defaults to false).
extended response = false

; ENABLE SSL ENCRYPTION - This option controls if SSL should be enabled.
use ssl = true

; COMMAND ALLOW NASTY META CHARS - This option determines whether or not the we will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments.
allow nasty characters = true

; PORT NUMBER - Port to use for NRPE.
port = 5666

; VERIFY MODE - Comma separated list of verification flags to set on the SSL socket.  none	The server will not send a client certificate request to the client, so the client will not send a certificate. peer	The server sends a client certificate request to the client and the certificate returned (if any) is checked. fail-if-no-cert	if the client did not return a certificate, the TLS/SSL handshake is immediately terminated. This flag must be used together with peer. peer-cert	Alias for peer and fail-if-no-cert. workarounds	Various bug workarounds. single	Always create a new key when using tmp_dh parameters. client-once	Only request a client certificate on the initial TLS/SSL handshake. This flag must be used together with verify-peer   
verify mode = none

; ALLOW INSECURE CHIPHERS and ENCRYPTION - Only enable this if you are using legacy check_nrpe client.
insecure = true

; COMMAND ARGUMENT PROCESSING - This option determines whether or not the we will allow clients to specify arguments to commands that are executed.
allow arguments = true


; Undocumented section
[/modules]

; Undocumented key
CheckHelpers = 0

; Undocumented key
CheckEventLog = 0

; NSCAClient - NSCA client can be used both from command line and from queries to submit passive checks via NSCA
NSCAClient = 1

; CheckExternalScripts - Execute external scripts
CheckExternalScripts = enabled

; NSClientServer - A server that listens for incoming check_nt connection and processes incoming requests.
NSClientServer = 1

; CheckSystem - Various system related checks, such as CPU load, process state, service state memory usage and PDH counters.
CheckSystem = 1

; CheckDisk - CheckDisk can check various file and disk related things.
CheckDisk = 1

; CheckNSCP - Use this module to check the healt and status of NSClient++ it self
CheckNSCP = 1

; NRPEServer - A server that listens for incoming NRPE connection and processes incoming requests.
NRPEServer = enabled


[NRPE Handlers]
check_exchange_mailqueue = cmd /c echo C:\nagiosscripts\Exch2016QueueHealth.ps1 | PowerShell.exe -Command -


; A list of scripts available to run from the CheckExternalScripts module. Syntax is: <command>=<script> <arguments>
[/settings/external scripts/scripts]

; SCRIPT - For more configuration options add a dedicated section (if you add a new section you can customize the user and various other advanced features)
default = 

; SCRIPT - For more configuration options add a dedicated section (if you add a new section you can customize the user and various other advanced features)
An alias is an internal command that has been predefined to provide a single command without arguments. Be careful so you don't create loops (ie check_loop = check_a, check_a=check_loop)


[/settings/external scripts/alias]

; ALIAS - Query alias
alias_volumes_loose = check_drivesize

; ALIAS - Query alias
alias_volumes = check_drivesize

; ALIAS - Query alias
alias_up = check_uptime

; ALIAS - Query alias
alias_sched_all = check_tasksched show-all "syntax=${title}: ${exit_code}" "crit=exit_code ne 0"

; ALIAS - Query alias
alias_process_count = check_process "process=$ARG1$" "warn=count > $ARG2$" "crit=count > $ARG3$"

; ALIAS - Query alias
alias_process = check_process "process=$ARG1$" "crit=state != 'started'"

; ALIAS - Query alias
alias_file_size = check_files "path=$ARG1$" "crit=size > $ARG2$" "top-syntax=${list}" "detail-syntax=${filename] ${size}" max-dir-depth=10

; ALIAS - Query alias
alias_service_ex = check_service "exclude=Net Driver HPZ12" "exclude=Pml Driver HPZ12" exclude=stisvc

; ALIAS - Query alias
alias_event_log = check_eventlog

; ALIAS - Query alias
alias_cpu = check_cpu

; ALIAS - Query alias
alias_mem = check_memory

; ALIAS - Query alias
default = 

; ALIAS - Query alias
alias_service = check_service

; ALIAS - Query alias
alias_process_stopped = check_process "process=$ARG1$" "crit=state != 'stopped'"

; ALIAS - Query alias
alias_sched_task = check_tasksched show-all "filter=title eq '$ARG1$'" "detail-syntax=${title} (${exit_code})" "crit=exit_code ne 0"

; ALIAS - Query alias
alias_disk_loose = check_drivesize

; ALIAS - Query alias
alias_sched_long = check_tasksched "filter=status = 'running'" "detail-syntax=${title} (${most_recent_run_time})" "crit=most_recent_run_time < -$ARG1$"

; ALIAS - Query alias
alias_disk = check_drivesize

; ALIAS - Query alias
alias_process_hung = check_process "filter=is_hung" "crit=count>0"

; ALIAS - Query alias
alias_cpu_ex = check_cpu "warn=load > $ARG1$" "crit=load > $ARG2$" time=5m time=1m time=30s

; ALIAS - Query alias
alias_file_age = check_files "path=$ARG1$" "crit=written > $ARG2$" "top-syntax=${list}" "detail-syntax=${filename] ${written}" max-dir-depth=10


; A list of templates for wrapped scripts.
[/settings/external scripts/wrappings]

; WRAPPING - An external script wrapping
vbs = cscript.exe //T:30 //NoLogo scripts\\lib\\wrapper.vbs %SCRIPT% %ARGS%

; WRAPPING - An external script wrapping
ps1 = cmd /c echo scripts\\%SCRIPT% %ARGS%; exit($lastexitcode) | powershell.exe -command -

; WRAPPING - An external script wrapping
bat = scripts\\%SCRIPT% %ARGS%


; Section for external scripts configuration options (CheckExternalScripts).
[/settings/external scripts]

; COMMAND ALLOW NASTY META CHARS - This option determines whether or not the we will allow clients to specify nasty (as in |`&><'"\[]{}) characters in arguments.
allow nasty characters = true

; COMMAND ARGUMENT PROCESSING - This option determines whether or not the we will allow clients to specify arguments to commands that are executed.
allow arguments = true

; COMMAND TIMEOUT - The maximum time in seconds that a command can execute. (if more then this execution will be aborted). NOTICE this only affects external commands not internal ones.
timeout = 60

; SCRIPT DIRECTORY - Load all scripts in a directory and use them as commands. Probably dangerous but useful if you have loads of scripts :)
script path = 


; Configure which services has to be in which state
[/settings/system/windows/service mapping]


; A set of options to configure the real time checks
[/settings/system/windows/real-time]


; Add counters to check
[/settings/system/windows/counters]


; Section for system checks and system settings
[/settings/system/windows]

; DEFAULT LENGTH - Used to define the default interval for range buffer checks (ie. CPU).
default buffer length = 1h


; Configure log file properties.
[/settings/log/file]

; MAXIMUM FILE SIZE - When file size reaches this it will be truncated to 50% if set to 0 (default) truncation will be disabled
max size = 0


; Configure log properties.
[/settings/log]

; LOG LEVEL - Log level to use. Available levels are error,warning,info,debug,trace
level = info

; DATEMASK - The size of the buffer to use when getting messages this affects the speed and maximum size of messages you can recieve.
date format = %Y-%m-%d %H:%M:%S

; FILENAME - The file to write log data to. Set this to none to disable log to file.
file name = ${exe-path}/nsclient.log


; Section for configuring the shared session.
[/settings/shared session]

; ENABLE THE SAHRED SESSION - This is currently not added in 0.4.x
enabled = false


; Section for configuring the crash handler.
[/settings/crash]

; SUBMISSION URL - The url to submit crash reports to
submit url = https://crash.nsclient.org/post

; RESTART SERVICE NAME - The url to submit crash reports to
restart target = NSCP

; RESTART - Submit crash reports to nsclient.org (or your configured submission server)
restart = true

; ARCHIVE CRASHREPORTS - Archive crash reports in the archive folder
archive = true

; SUBMIT CRASHREPORTS - Submit crash reports to nsclient.org (or your configured submission server)
submit = false

; CRASH ARCHIVE LOCATION - The folder to archive crash dumps in
archive folder = ${shared-path}/crash-dumps


; Target definition for: default
[/settings/NSCA/client/targets/default]

; ENCRYPTION - Name of encryption algorithm to use. Has to be the same as your server i using or it wont work at all.This is also independent of SSL and generally used instead of SSL. Available encryption algorithms are: none = No Encryption (not safe) xor = XOR des = DES 3des = DES-EDE3 cast128 = CAST-128 xtea = XTEA blowfish = Blowfish twofish = Twofish rc2 = RC2 aes128 = AES aes192 = AES aes = AES serpent = Serpent gost = GOST
encryption = aes

; ENABLE SSL ENCRYPTION - This option controls if SSL should be enabled.
use ssl = false

; VERIFY MODE - Target definition for: default
verify mode = none

; ALLOWED CIPHERS - A better value is: ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH
allowed ciphers = ADH

; TARGET ADDRESS - Target host address
address = 

; PASSWORD - The password to use. Again has to be the same as the server or it wont work at all.
password = 

; SSL CERTIFICATE - Target definition for: default
certificate = 

; TIMEOUT - Timeout when reading/writing packets to/from sockets.
timeout = 30


; A set of filters to use in real-time mode
[/settings/system/windows/real-time/checks]


; Section for NSClient (NSClientServer.dll) (check_nt) protocol options.
[/settings/NSClient/server]

; ENABLE SSL ENCRYPTION - This option controls if SSL should be enabled.
use ssl = false

; PERFORMANCE DATA - Send performance data back to Nagios (set this to 0 to remove all performance data).
performance data = true

; PORT NUMBER - Port to use for check_nt.
port = 12489


; Section for NSCA passive check module.
[/settings/NSCA/client]

; HOSTNAME - The host name of the monitored computer. Set this to auto (default) to use the windows name of the computer.  auto	Hostname ${host}	Hostname ${host_lc} Hostname in lowercase ${host_uc}	Hostname in uppercase ${domain}	Domainname ${domain_lc}	Domainname in lowercase ${domain_uc}	Domainname in uppercase 
hostname = auto

; CHANNEL - The channel to listen to.
channel = NSCA


; Files to be included in the configuration
[/includes]


; A list of wrapped scripts (ie. scruts using a template mechanism). The template used will be defined by the extension of the script.
[/settings/external scripts/wrapped scripts]


[/paths]

; Path for certificate-path - 
certificate-path = ${shared-path}/security

; Path for crash-folder - 
crash-folder = C:\Program Files\NSClient++

; Path for base-path - 
base-path = C:\Program Files\NSClient++

; Path for module-path - 
module-path = ${shared-path}/modules

; Path for shared-path - 
shared-path = C:\Program Files\NSClient++

; Path for exe-path - 
exe-path = C:\Program Files\NSClient++
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: Powershell performance script - exchange monitoring scri

Post by mcapra »

Here's the official documentation for running external scripts with NSClient++ and check_nrpe:
https://support.nagios.com/kb/article.php?id=528

It looks like you still need to define your Powershell script under the [/settings/external scripts/scripts] section. Please refer to the "PowerShell Script" section of the above documentation and let us know if you have additional questions or if something is unclear or not working correctly.

Be sure to restart the NSClient++ service once any changes are made to the NSClient++ configuration file.
Former Nagios employee
https://www.mcapra.com/
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Powershell performance script - exchange monitoring scri

Post by lmiltchev »

Copy the script that you downloaded from the Nagios Exchange to the NSClient++ scripts directory. Make sure it works when run locally on the Windows machine. Add a command to the nsclient.ini file under the [/settings/external scripts/scripts] section, for example:

Code: Select all

check_queue_health = cmd /c echo scripts\NagiosMonitoring_Exchange2016QueueHealth_V2.2.ps1; exit $LastExitCode | powershell.exe -command -
Save, exit and restart NSClient++ service so that changes can take effect.

Test it from the command line on the Nagios XI server by running:

Code: Select all

/usr/local/nagios/libexec/check_nrpe - H <ip address> -c check_queue_health
Let us know if you have any more questions. Thank you!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Tune
Posts: 15
Joined: Wed Nov 02, 2016 9:53 am

Re: Powershell performance script - exchange monitoring scri

Post by Tune »

Many thanks
The manual checked
check_queue_health = cmd /c echo scripts\NagiosMonitoring_Exchange2016QueueHealth_V2.2.ps1; exit $LastExitCode | powershell.exe -command -

Worked!

The
/usr/local/nagios/libexec/check_nrpe -H <ip address> -c check_queue_health
Also worked

But the script does not show in nagios, I have been waiting an hour to see if it is there, it is not?
Could it be related to a combination of SNMP monitoring and Nsclient++ monitoring?
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Powershell performance script - exchange monitoring scri

Post by lmiltchev »

Once you've tested your command from the command line, and confirmed that it works, the next step would be to create a new command (if needed) on the Nagios side of things, and a new check (service). In order to find out how to do this, please refer to our official "Managing Plugins In Nagios XI" document below:

https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Let us know if you get stuck on something. Thank you!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Tune
Posts: 15
Joined: Wed Nov 02, 2016 9:53 am

Re: Powershell performance script - exchange monitoring scri

Post by Tune »

After I uploaded the powershell plugin, I cannot see it commands, I suspect the error is in "Manage Plugins" Owner/Group/Permissions are not the same. I will fix this myself using WinSCP and change the file/group permission that way.

I do get it, and this should be very simple, the guide surely is, it is a simple 4 steps.

For a non application programmer like me, I do not get what Nagios Expect, what the scripts wants and settings.

I believe that it would greatly add quality to Nagios, that such a simple guide also were a requirement for plugin developers, it is not an overly complex guide.

My time for getting this to work, is 5 hours+ and I am not done yet, an experienced application developer might do it less than 10 minutes.
Tune
Posts: 15
Joined: Wed Nov 02, 2016 9:53 am

Re: Powershell performance script - exchange monitoring scri

Post by Tune »

I got one of my developers and we got it to work.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Powershell performance script - exchange monitoring scri

Post by scottwilkerson »

Glad ot hear this is resolved.

Locking
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked