Page 1 of 1

Create a new command in nagios

Posted: Tue Apr 11, 2017 8:00 am
by W.W.
Hi

I am little new on nagios and I would like to create a new command. I already have to try but no result. I have defines the command in the file commands.cfg but every time I have an error message in nagios interface web which tells me unknown command.
For example I wanted to create a new command “checkfilesize” here is how I have to proceed
I have defines this command

Code: Select all

define command {
  command_name CheckFileSize
  command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c CheckFileSize -a ShowAll MaxCrit=$ARG1$ File:$ARG2$=$ARG3$
}

Then I have defines the service in the file conf of the machine concerned

Code: Select all

define service{
      use                               generic-service
      host_name                    $HOSTNAME
      service_description        CheckFolder
      check_command           check_nrpe!CheckFileSize -H $HOSTADRRESS -p 5666 -c CheckFileSize -a ShowAll MaxCrit=!1G!Win!=C:\\CheckFolder
}
Restart nagios service and type the following command on nagios server

Code: Select all

check_nrpe!CheckFileSize -H $HOSTADRESS -p 5666 -c CheckFileSize -a ShowAll MaxCrit=1G File:Win=D:\\Folder\\To\\Check
I got this error

Code: Select all

-bash: !CheckFileSize: event not found

I am a little lost here, if somebody can help me that would be cool thank you in advance.
Here is my config I have an nsclient++ 0.5.62 configured on my remote machine (windows 7), and an nagios 4.1 installed on centos 6.8 and this topic show exactly what I want to do https: // forums.monitoring-fr.org / index.php? Topic=227.0

Re: Create a new command in nagios

Posted: Tue Apr 11, 2017 9:14 am
by tacolover101
you seem to have your $ARG#$ variables mixed up.

Code: Select all

command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c CheckFileSize -a ShowAll MaxCrit=$ARG1$ File:$ARG2$=$ARG3$
in this example you are passing $ARG1$, 2, and 3.

Code: Select all

 check_command           check_nrpe!CheckFileSize -H $HOSTADRRESS -p 5666 -c CheckFileSize -a ShowAll MaxCrit=!1G!Win!=C:\\CheckFolder
now on the service level, you have just told nagios that CheckFileSize -H $HOSTADRRESS -p 5666 -c CheckFileSize -a ShowAll MaxCrit=!1G!Win!=C:\\CheckFolder is $ARG1$. this will not work. you need to fix them accordingy. on a service level with the check_command, each section seperated by a ! represnets a new value. for example - check_nrpe!arg1!arg2!arg3!

Re: Create a new command in nagios

Posted: Tue Apr 11, 2017 10:03 am
by W.W.
Thank u for the reply tacolover101

Ok, I undustand what you ask me to do but I don't see how to do it. Where should I put the ! in check_command ?

Re: Create a new command in nagios

Posted: Tue Apr 11, 2017 10:54 am
by mcapra
W.W. wrote:I have defines the command in the file commands.cfg but every time I have an error message in nagios interface web which tells me unknown command.
Did you create the Command definition in the file itself, or did you use the Core Config Manager? Everything in Nagios XI is done through the Core Config Manager; You never need to touch flat files. If you modified commands.cfg only, that's why the GUI is complaining. The GUI only has a concept of what's been added/deleted/modified via the Core Config Manager.

If you still want to do things in flat files, there's specific ways to handle that in Nagios XI:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf

Re: Create a new command in nagios

Posted: Wed Apr 12, 2017 6:45 am
by W.W.
I create the command definition in the command.cfg file and only in this file. Do I have create it somewhere else ?

Re: Create a new command in nagios

Posted: Wed Apr 12, 2017 11:26 am
by mcapra
Yup, you will need to create it through the Core Config Manager like so:
2017_04_12_11_25_48_CCM_Nagios_XI.png

Re: Create a new command in nagios

Posted: Thu Apr 13, 2017 2:07 am
by W.W.
Ok, I did it and it's work now thanks

Re: Create a new command in nagios

Posted: Thu Apr 13, 2017 12:44 pm
by cdienger
Thanks for the update. Was there anything else we can help with or can the thread be closed?

Re: Create a new command in nagios

Posted: Fri Apr 14, 2017 6:50 am
by W.W.
Yep you can close it.