Windows passing dynamic file name to nagios plugin

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
mrjsokol
Posts: 109
Joined: Thu Apr 16, 2020 10:27 am

Windows passing dynamic file name to nagios plugin

Post by mrjsokol »

Hello all,
I havent came across a windows topic about being able to pass a dynamically set variable in windows to nagios so hoping to find some direction. I have a script that generates a system var and then want to send that system var value to nagios to be used as part of a file path. When I use that variable in the passive config file, the variable is not translated, it is read as literal text. Is there a method to extract the value and send to nagios to be part of the file name that the nagios log plugin looks for?
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Windows passing dynamic file name to nagios plugin

Post by benjaminsmith »

Hello @mrjsokol,
I have a script that generates a system var and then want to send that system var value to nagios to be used as part of a file path
I think this would be a good application for a simple wrapper script for the plugin you are using, so instead of directly running the plugin, you configure Nagios to call the wrapper script which feeds the system var into the file path for your check command. Let me know how that sounds. Also, if you can post the passive configuration for this check so we can review the command, that would be very helpful.

Thanks,
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Windows passing dynamic file name to nagios plugin

Post by benjaminsmith »

Hello @mrjsokol,
I have a script that generates a system var and then want to send that system var value to nagios to be used as part of a file path
I think this would be a good application for a simple wrapper script for the plugin you are using, so instead of directly running the plugin, you configure Nagios to call the wrapper script which feeds the system var into the file path for your check command. Let me know how that sounds. Also, if you can post the passive configuration for this check so we can review the command, that would be very helpful.

Thanks,
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Windows passing dynamic file name to nagios plugin

Post by benjaminsmith »

Hello @mrjsokol,
I have a script that generates a system var and then want to send that system var value to nagios to be used as part of a file path
I think this would be a good application for a simple wrapper script for the plugin you are using, so instead of directly running the plugin, you configure Nagios to call the wrapper script which feeds the system var into the file path for your check command. Let me know how that sounds. Also, if you can post the passive configuration for this check so we can review the command, that would be very helpful.

Thanks,
Benjamin
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
mrjsokol
Posts: 109
Joined: Thu Apr 16, 2020 10:27 am

Re: Windows passing dynamic file name to nagios plugin

Post by mrjsokol »

The passive config command sent to nagios is: %HOSTNAME%|logic_Log|60 = plugins/check_log3.exe?match=search&args=-l %CurrlogicName% --pattern=Exception|Offline|Error %Y-%m-%d.trace

Do you think you could provide an example of what this wrapper class would look like and how would it interface with nagios? would it be directly included in the passive file or would this wrapper class be called in a different manner?
benjaminsmith
Posts: 5324
Joined: Wed Aug 22, 2018 4:39 pm
Location: saint paul

Re: Windows passing dynamic file name to nagios plugin

Post by benjaminsmith »

HI,

So normally, you would just call another simple script, and then that would run the plugins modify the behavior or output as required. Sor for example, the would-be something like:

Code: Select all

%HOSTNAME%|logic_Log|60 = plugins/wrapper.ps1
Then this script would run the check_log3.exe program and feeding the appropriate arguments and return valid results to send to Nagios XI. In this case, the script would have to generate the dynamic system var. Hopefully, that would be possible but I'm not 100% on the setup here. Which variable is the one not getting passed correctly, %CurrlogicName%?

The following page has some good information about configuring Windows plugin scripts with NCPA.

https://support.nagios.com/kb/article/n ... a-722.html

Reference:
How to write a bash script wrapper
As of May 25th, 2018, all communications with Nagios Enterprises and its employees are covered under our new Privacy Policy.

Be sure to check out our Knowledgebase for helpful articles and solutions!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: Windows passing dynamic file name to nagios plugin

Post by ssax »

Code: Select all

%HOSTNAME%|logic_Log|60 = plugins/wrapper.ps1
Here's an example wrapper for you:

Code: Select all

# Change $Env:PATH to $Env:YOUR_ENVIRONMENTAL_VARIABLE
# Change 'echo $IDENTIFIER' to your check command, use $IDENTIFIER variable in the check  

$IDENTIFIER = $Env:PATH
$OUTPUT = cmd /c echo $IDENTIFIER 2`>`&1
$EXIT_CODE = $LASTEXITCODE
Write-Host "$OUTPUT"
exit $EXIT_CODE
Here are the plugin development links I was referring to:

https://assets.nagios.com/downloads/nag ... inapi.html

https://nagios-plugins.org/doc/guidelines.html

Let us know if you have any questions.

Thank you!
mrjsokol
Posts: 109
Joined: Thu Apr 16, 2020 10:27 am

Re: Windows passing dynamic file name to nagios plugin

Post by mrjsokol »

Hey Guys thanks for the help! Got a solution implemented. This thread can be locked.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Windows passing dynamic file name to nagios plugin

Post by scottwilkerson »

mrjsokol wrote:Hey Guys thanks for the help! Got a solution implemented. This thread can be locked.
Great!

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