-1

I'm a Nagios newbie and after reading several doc about hosts, services, commands definitions I came across a pretty dumb error which I can't get pass by.

I followed this tutorial: Official Nagios Tuto

Here is my nagios.cfg code (just a sample, not all the conf):

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/timperiodds.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg

Now my hosts.cfg:

define host {
    host_name         nas_01
    alias             NAS Eth0
    address           192.168.1.x     ; I did not put 'x' ;)
}

Finally my services.cfg:

define service {
    use                 generic-service     ; Inherit default values from a template
    host_name           nas_01
    service_description HTTP
    check_command       check_http
}

I try to validate the conf file using: /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

But I get this error:

Error: Invalid max_check_attempts value for host 'nas_01'
Error: Could not register host (config file '/usr/local/nagios/etc/objects/hosts.cfg', starting on line 7)

If I try to put my host definition in my services.cfg I have the following error:

Warning: Duplicate definition found for host 'nas_01' (config file '/usr/local/nagios/etc/objects/services.cfg', starting on line 7)
Error: Could not add object property in file '/usr/local/nagios/etc/objects/services.cfg' on line 9.
Error: Invalid max_check_attempts value for host 'nas_01'
Error: Could not register host (config file '/usr/local/nagios/etc/objects/hosts.cfg', starting on line 7)
   Error processing object config files!

Something seems shady with max_check_attempts no?

Any ideas?

  • You definition seems to be correct. Are you sure that `hosts.cfg` is in `/usr/local/nagios/etc/objects/` directory? – Rohlik Apr 14 '20 at 06:22
  • Yes, it is .... `-rw-rw-r-- 1 nagios nagios 6.6k Apr 12 17:07 commands.cfg` `-rw-rw-r-- 1 nagios nagios 1.8k Apr 12 17:07 contacts.cfg` `-rw-rw-r-- 1 nagios nagios 286 Apr 12 17:07 hosts.cfg` `-rw-rw-r-- 1 nagios nagios 4.7k Apr 12 17:07 localhost.cfg` `-rw-rw-r-- 1 nagios nagios 522 Apr 12 17:07 services.cfg` `-rw-rw-r-- 1 nagios nagios 13k Apr 12 17:07 templates.cfg` `-rw-rw-r-- 1 nagios nagios 3.5k Apr 12 17:07 timeperiods.cfg` – steackfrite Apr 14 '20 at 07:15
  • `/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg` should show number of all hosts. Can you verify if that number is correct? – Rohlik Apr 14 '20 at 17:24
  • I can't see any host list with `/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg` This is the command I issue to check the conf and it's giving me the error showed before. I could give you all the output but I doubt it would be useful. Could it be a space/tab error? I tried several conf but with no success. – steackfrite Apr 14 '20 at 18:44
  • Try put your hosts definition (code) inside `services.cfg` file. – Rohlik Apr 14 '20 at 19:32
  • Hi @Rohlik and thanks for your time & help. I updated my initial post so it would be more clear than posting the results in a comment. Basically, when I put my host definition in my services I have an duplicate host error and an invalid max_check_attempts value error . – steackfrite Apr 15 '20 at 07:29
  • No problem mate. It is nice to hear that you resolve your problem. Do not forget to mark your answer as solution ;-) – Rohlik Apr 15 '20 at 11:26

1 Answers1

0

Alright, so it was nothing...

Basically I forgot to put the 'use linux-server' in my hosts.cfg so it fails because it misses several mandatory attributes such as max_check_attempts.

hosts.cfg:

define host {
    use                     linux-server
    host_name               nas_01
    alias                   NAS Eth02 
    address                 192.168.1.16
}

services.cfg:

define service {
    use                     generic-service
    host_name               nas_01
    service_description     HTTP Check
    check_command           check_http
}

Thanks a lot to @Rohlik as he put me on the right way!

Cheers