Page 1 of 1
Windows passing dynamic file name to nagios plugin
Posted: Fri Aug 14, 2020 3:20 pm
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?
Re: Windows passing dynamic file name to nagios plugin
Posted: Mon Aug 17, 2020 2:00 pm
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
Re: Windows passing dynamic file name to nagios plugin
Posted: Mon Aug 17, 2020 2:02 pm
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
Re: Windows passing dynamic file name to nagios plugin
Posted: Mon Aug 17, 2020 2:02 pm
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
Re: Windows passing dynamic file name to nagios plugin
Posted: Tue Aug 18, 2020 9:45 am
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?
Re: Windows passing dynamic file name to nagios plugin
Posted: Wed Aug 19, 2020 10:29 am
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
Re: Windows passing dynamic file name to nagios plugin
Posted: Fri Aug 21, 2020 10:13 am
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!
Re: Windows passing dynamic file name to nagios plugin
Posted: Wed Aug 26, 2020 7:05 am
by mrjsokol
Hey Guys thanks for the help! Got a solution implemented. This thread can be locked.
Re: Windows passing dynamic file name to nagios plugin
Posted: Wed Aug 26, 2020 7:08 am
by scottwilkerson
mrjsokol wrote:Hey Guys thanks for the help! Got a solution implemented. This thread can be locked.
Great!
Locking thread