Page 4 of 5

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

Posted: Mon Mar 14, 2016 1:59 pm
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.

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

Posted: Mon Mar 14, 2016 2:02 pm
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.

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

Posted: Mon Mar 14, 2016 2:30 pm
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.

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

Posted: Mon Mar 14, 2016 3:30 pm
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. :)

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

Posted: Tue Mar 15, 2016 10:29 am
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

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

Posted: Tue Mar 15, 2016 4:23 pm
by hsmith
It should be in your commands.cfg file.

/usr/local/nagios/etc/commands.cfg in most cases.

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

Posted: Wed Mar 16, 2016 10:28 am
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

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

Posted: Wed Mar 16, 2016 10:53 am
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/?

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

Posted: Wed Mar 16, 2016 11:46 am
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' ./?

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

Posted: Wed Mar 16, 2016 12:23 pm
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.