Riccardo Locatelli
Riccardo Locatelli

Reputation: 1

nagios how repeat check service more time different argument

I have one host on nagios defined like that:

define host {
    host_name                       my-host
    address                         ip
    display_name                    my-host
    hostgroups                      windows,windows-process-count
    use                             windows-server
    _PROCESSNAME                    my-process1.exe
    _PROCESSCOUNT                   1

}

On this host I check only that my-process1.exe is up. but I need to check more process (my-process1, my-process2 etc....) I would like check more process, defining like that:

    define host {
    host_name                       my-host
    address                         ip
    display_name                    my-host
    hostgroups                      windows,windows-process-count
    use                             windows-server
    _PROCESSNAME                    my-process1.exe
    _PROCESSCOUNT                   1
    _PROCESSNAME2                   my-process2.exe
    _PROCESSCOUNT2                  1
    _PROCESSNAME2                   my-process3.exe
    _PROCESSCOUNT2                  4
    etc...... for x process that i must control on this server

}

but in this way i must define x services, x hostgroups and x commands. This is very uncomfortable and not very elegant.

what is the best way to get this result?

Upvotes: 0

Views: 415

Answers (1)

Jorge Valentini
Jorge Valentini

Reputation: 427

Unfortunately I don't think there is an elegant way to do it as you would like to. I have always worked with Nagios using a service-oriented approach, means I define a monitoring for one service or process and then I link all the hosts or hostgroups that use that process and need monitoring, even if it is one server. For me, I found that as the most reliable, tidy and sustainable way.

If you can afford a generic alert when any of the service fails, you could prepare a custom command to check all of them in one separate script, I would not like to see it like this in my dashboard.

I know that it is what you want to avoid but, If I were you, and considering you have a single server to monitor these processes, I would prepare a separate service file, something like:

#!/bin/bash

srvCfg = "/etc/nagios3/conf.d/host1procs.cfg" # I am using Nagios over Debian
server="host1"
processes=("process1.exe" "process2.exe")
srvGroup="customservicegroup"

for proc in "${processes[@]}"; do
    echo "define service{" >> $srvCfg
    echo "  use             generic-service" >> $srvCfg
    echo "  host_name       $server" >> $srvCfg
    echo "  servicegroups       $srvGroup" >> $srvCfg
    echo "  service_description Process monitoring for $proc" >> $srvCfg
    echo "  check_command  check_nt!PROCSTATE!-d SHOWALL -l $proc" >> $srvCfg
    echo "}" >> $srvCfg
done

I assumed that your example is just an example and the process names are not actually iterable to generate the list. That script will result in a file like:

define service{
  use           generic-service
  host_name     host1
  servicegroups     customservicegroup
  service_description   Process monitoring for process1.exe
  check_command  check_nt!PROCSTATE!-d SHOWALL -l process1.exe
}
define service{
  use           generic-service
  host_name     host1
  servicegroups     customservicegroup
  service_description   Process monitoring for process2.exe
  check_command  check_nt!PROCSTATE!-d SHOWALL -l process2.exe
}

You will have to define the servicegroup if you want all of the services to be automatically in it, if not take out the servicegroups line.

I know it is not the answer you are looking for, but hope it helps

Upvotes: 1

Related Questions