Page 1 of 1

Passing Powershell script args to Nagios XI

Posted: Fri Nov 06, 2020 3:48 am
by G_Deshpande
Gents,

We have Powershell script to monitor folder & files within it present on windows server which has hard coded values of Directory/folder path, i want to pass these hard coded values present in script as an argument in Nagios XI while configuring/monitoring script.
Because every time i have to change code/path of folders in script on server, instead of that if i would have facility to pass in Nagios XI dynamically it would be great.

Sample Script of hard codded path-
param($Parentfolder='C:\Users\Desktop\projects',$subfolder='TEST',$flag='inclusion',$file_list=@('aaa','bbb','ccc'))
$searchfolder = $Parentfolder + '\' + $subfolder + '\'

I want to pass parent folder, Subfolder values & folder inclusion list in Nagios itself, how to achieve this?

Nagios XI- using 5.7.4 version
Using NRPE I am implementing powershell script

check_nrpe!Test_ps1!

I wish to pass folder path & folder inclusion list mentioned in the script to above syntax after check_nrpe!Test_ps1!

Re: Passing Powershell script args to Nagios XI

Posted: Fri Nov 06, 2020 1:40 pm
by benjaminsmith
Hi @G_Deshpande,

You can achieve this by using either Macros or Custom Variables in Nagios XI to pass those directory paths. Below is a link to the documentation to help get you started. Let us know if you get it working or have any questions.

Understanding User Macros

Custom Object Variables

Benjamin

Re: Passing Powershell script args to Nagios XI

Posted: Mon Nov 09, 2020 5:34 am
by G_Deshpande
Thanks for revert.

Macros will be good option when an argument you are passing is constant value like $userx but in my case i will be using different directory paths & include, exclude folder name list as well.

I have used environment variables before but with event handlers, in my case i am not using any event handler to perform any action.

Can you suggest something easy to achieve approach where instead of mentioning different paths in scrip, i can pass in Nagios command?

Or do you have any example for this, how i can pass these values ?

Re: Passing Powershell script args to Nagios XI

Posted: Mon Nov 09, 2020 3:44 pm
by benjaminsmith
Hi,

Normally, in this type of case, if I'm understanding the context correctly, this would be handled by the custom plugin or Test_ps1. You pass any required arguments to this script and then it would run the appropriate tests and return the results to Nagios.

For example,

Code: Select all

check_nrpe -H <ipaddress> -c test_ps1 -a <optional arguments 1,2,3....8>
Reference:
NRPE - Configuring NRPE Commands To Accept Arguments