How to turn on/off Nagios service/notification by Curl from commandline

The content of this writing is just include the steps to perform it from the comamndline. I was stuck few months back with that requirement and my client gave me that code (S)he found in Serverfault site.So I went on to put some wrapper around it to make it more interactive.Although the actual requirement was not like that.

Anyway, here is the piece that do the things for me…I am not sure it might work for you…but trying something uncanny thing is not a bad thing at all…provided it’s not a production base.I must confess Nagios is not my forte…I can manage it to some extents.

curl -d " cmd_mod=2cmd_type=56&host=$HOSTNAME&service=$SERVICENAME&btnSubmit=commit" "Url of the nagios server" "username:password"

Every cmd_type number is paired i.e if up is 56 then down is 57 something like that.Like every other action has different cmd_type number attached to it.Now the biggest thing about this ..you need to know the cmd_type number by looking the browser nagios web interface by pointing your cursor over the specific entry. So the above code I put in a wrapper script which basically asking the person to input the hostname, which will be stored in $HOSTNAME variable and the service name ,which will store in the $SERVICENAME variable and of course the cmd_type. Then it will perform the task and show the result in the terminal itself. Now you can go back in the browser and check that it got effected.

Now one more time I was asked by the client to fix the downtime of any particular nagios host from the help of above script…oooops a big ooops… because the downtime command take more mandatory parameter along with the standard one.So I had to accommodate that..so I asked help in the forum and someone replied to me..you can find the reply here : http://stackoverflow.com/questions/6842683/how-to-set-downtime-for-any-specific-nagios-host-for-certain-time-from-commandlin

Hope this help.

Cheers!
Bhaskar

About unixbhaskar
GNU/Linux Consultant

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: