These definition can be placed in their own file or added to

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: These definition can be placed in their own file or adde

Post by rkennedy »

You'll want to define a command like so -

Code: Select all

define command {
       command_name                           check_mssql_job
       command_line                             $USER1$/check_mssql_job_history.py -H $HOSTADDRESS$ $ARG1$
}
The service definition would use this as the check command -

Code: Select all

       check_command                            check_mssql_job! -U mssqlUser -P mssqlPassword
That should work for you, let us know if you run into any issues.
Former Nagios Employee
bmurtha
Posts: 27
Joined: Tue Feb 23, 2016 11:08 am

Re: These definition can be placed in their own file or adde

Post by bmurtha »

This looks great but where do I put it? In /usr/local/nagios/libexec ? Should it use a file extension? Sorry I'm new to Nagios.
bmurtha
Posts: 27
Joined: Tue Feb 23, 2016 11:08 am

Re: These definition can be placed in their own file or adde

Post by bmurtha »

I'm assuming $User1$ expands to /usr/local/nagios/libexec
-H $HostAddress$ expands to my IP or I have to replace it?
-A $Args1$ is going to expand to what is in command_name? I'm new to this so please forgive me if my questions are stupid.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: These definition can be placed in their own file or adde

Post by rkennedy »

rkennedy wrote:You'll want to define a command like so -

Code: Select all

define command {
       command_name                           check_mssql_job
       command_line                             $USER1$/check_mssql_job_history.py -H $HOSTADDRESS$ $ARG1$
}
The service definition would use this as the check command -

Code: Select all

       check_command                            check_mssql_job! -U mssqlUser -P mssqlPassword
That should work for you, let us know if you run into any issues.
bmurtha wrote:I'm assuming $User1$ expands to /usr/local/nagios/libexec
-H $HostAddress$ expands to my IP or I have to replace it?
-A $Args1$ is going to expand to what is in command_name? I'm new to this so please forgive me if my questions are stupid.
No problem. you got it! $USER1$ will expand to that directory. It pulls the reference from /usr/local/nagios/etc/resource.cfg. You could also define other $USER#$ variables in that file, to masquerade a password for example.

$HOSTADDRESS$ will be pulled from the the address part under your host definition.

$ARG1$ will pull from anything after the ! in our check command. Once another ! is present, $ARG2$ will exist. For example -

Code: Select all

       check_command                            check_mssql_job! -U mssqlUser -P mssqlPassword!second!third

Code: Select all

$ARG1$ = ' -U mssqlUser -P mssqlPassword'
$ARG2$ = 'second'
$ARG3$ = 'third'
bmurtha wrote:This looks great but where do I put it? In /usr/local/nagios/libexec ? Should it use a file extension? Sorry I'm new to Nagios.
The standardization that Core deploys with, is all of your commands located in /usr/local/nagios/etc/commands.cfg. From there, you can create any file to hold your host / service definitions. The one key part, is making sure it's referenced in the /usr/local/nagios/etc/nagios.cfg file.

For example, you should see this part in your nagios.cfg -

Code: Select all

# OBJECT CONFIGURATION FILE(S)
# These are the object configuration files in which you define hosts,
# host groups, contacts, contact groups, services, etc.
# You can split your object definitions across several config files
# if you wish (as shown below), or keep them all in a single config file.

# You can specify individual object config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg

# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg

# Definitions for monitoring a Windows machine
#cfg_file=/usr/local/nagios/etc/objects/windows.cfg

# You can specify individual object config files as shown below:
#cfg_dir=/usr/local/nagios/etc/servers
You are free to organize this in any way that you want. The two important things here are cfg_file, and cfg_dir. This is how you include a file to work with Nagios Core. I recommend creating a /usr/local/nagios/etc/servers folder, and uncommenting the line above #cfg_dir=/usr/local/nagios/etc/servers.

At this point, you can place any configuration files into that servers folder, and they will be picked up by Core.

Once you uncomment the servers folder, and have created it - you can now create a configuration file to use. Call this hostname.cfg for example. Something like this should suffice -

Code: Select all

define host {
        use                             linux-server
        host_name                       hostnamehere
        alias                           alias for this host
        address                         1.2.3.4
        max_check_attempts              5
        check_period                    24x7
        notification_interval           30
        notification_period             24x7
}
define service {
        use                             generic-service
        host_name                       hostnamehere
        service_description             MSSQLJOB
        check_command                   check_mssql_job! -U mssqlUser -P mssqlPassword
}
Then, make sure to add to the bottom of your /usr/local/nagios/etc/objects/commands.cfg -

Code: Select all

define command {
       command_name                           check_mssql_job
       command_line                             $USER1$/check_mssql_job_history.py -H $HOSTADDRESS$ $ARG1$
}
Run a service nagios restart, and if no errors were detected you should now have the command check_mssql_job with a host / service corresponding to it.

I tried to explain this pretty thorough -- let me know if you have any further questions. None are stupid. :)
Former Nagios Employee
bmurtha
Posts: 27
Joined: Tue Feb 23, 2016 11:08 am

Re: These definition can be placed in their own file or adde

Post by bmurtha »

I'm trying to remove the old service command definition for the old java class that I was using and replace it with the new service/command definition I have here. I remember reading over the docs to figure out how to do this, and somehow I did but I can't remember what it was I did?


Checking objects...
Error: Service check command 'check_sqllog!myUser!myPassword' specified in service 'Failed_Jobs' for host '10.32.35.180' not defined anywhere!

where should I look to find this definition?
Thanks for the help,
Regards,
Bryan
User avatar
hsmith
Agent Smith
Posts: 3539
Joined: Thu Jul 30, 2015 11:09 am
Location: 127.0.0.1
Contact:

Re: These definition can be placed in their own file or adde

Post by hsmith »

It should be in your commands.cfg file.

/usr/local/nagios/etc/commands.cfg in most cases.
Former Nagios Employee.
me.
bmurtha
Posts: 27
Joined: Tue Feb 23, 2016 11:08 am

Re: These definition can be placed in their own file or adde

Post by bmurtha »

No I switched out the old command for job failed with this one:


define command{
command_name check_mssql_job
command_line $USER1$/check_mssql_job_history.py -H $HOSTADDRESS$ $ARG1$
}

I'm wondering where else I should look for this definition?

Sorry for the newbie question,
Bryan
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: These definition can be placed in their own file or adde

Post by rkennedy »

Can you post the entire contents of whatever file contains the 'Failed_Jobs' service? What is the output of grep -R 'Failed_Jobs' /usr/local/nagios/etc/?
Former Nagios Employee
bmurtha
Posts: 27
Joined: Tue Feb 23, 2016 11:08 am

Re: These definition can be placed in their own file or adde

Post by bmurtha »

[root@localhost etc]# grep -R 'Failed_Jobs' /usr/local/nagios/etc/?
grep: /usr/local/nagios/etc/?: No such file or directory
[root@localhost etc]# cd /
[root@localhost /]# grep -R 'Failed_Jobs' /usr/local/nagios/etc/?
grep: /usr/local/nagios/etc/?: No such file or directory
[root@localhost /]# cd /usr/local/nagios/etc
[root@localhost etc]# grep -R 'Failed_Jobs' ./?
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: These definition can be placed in their own file or adde

Post by rkennedy »

The command you need to run is grep -R 'Failed_Jobs' /usr/local/nagios/etc/

Without the ?. That was part of my question.
Former Nagios Employee
Locked