Changing localhost in Nagios console to the hostname

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.
Locked
esauve
Posts: 3
Joined: Tue Sep 17, 2013 12:51 pm

Changing localhost in Nagios console to the hostname

Post by esauve »

I apologize in advance if this has been asked a gazillion times before, I did search this forum and Googled before asking this question.

I'd like my Nagios server to show up up "Hosts" (in the Console) with its actual hostname not as "localhost", I tried modifying the localhost.cfg file but the nagios startup script/daemon refuses to start after I make the modification. Thanks in advance.
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Changing localhost in Nagios console to the hostname

Post by abrist »

What errors do you receive when you "apply configuration"?

Code: Select all

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
esauve
Posts: 3
Joined: Tue Sep 17, 2013 12:51 pm

Re: Changing localhost in Nagios console to the hostname

Post by esauve »

Below is the output (no errors, only a few warnings):
[root@cabro1mon0001 ~]# nagios -v /etc/nagios/nagios.cfg

Nagios Core 3.5.0
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 03-15-2013
License: GPL

Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config file '/etc/nagios/objects/commands.cfg'...
Processing object config file '/etc/nagios/objects/contacts.cfg'...
Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
Processing object config file '/etc/nagios/objects/templates.cfg'...
Processing object config file '/etc/nagios/objects/localhost.cfg'...
Processing object config directory '/etc/nagios/servers'...
Processing object config file '/etc/nagios/servers/clients.cfg'...
Processing object config directory '/etc/nagios/conf.d'...
Read object config files okay...

Running pre-flight check on configuration data...

Checking services...
Checked 8 services.
Checking hosts...
Warning: Host 'a' has no services associated with it!
Warning: Host 'b' has no services associated with it!
Warning: Host 'c' has no services associated with it!
Warning: Host 'd' has no services associated with it!
Warning: Host 'e' has no services associated with it!
Warning: Host 'f' has no services associated with it!
Checked 7 hosts.
Checking host groups...
Checked 1 host groups.
Checking service groups...
Checked 0 service groups.
Checking contacts...
Checked 1 contacts.
Checking contact groups...
Checked 1 contact groups.
Checking service escalations...
Checked 0 service escalations.
Checking service dependencies...
Checked 0 service dependencies.
Checking host escalations...
Checked 0 host escalations.
Checking host dependencies...
Checked 0 host dependencies.
Checking commands...
Checked 24 commands.
Checking time periods...
Checked 5 time periods.
Checking for circular paths between hosts...
Checking for circular host and service dependencies...
Checking global event handlers...
Checking obsessive compulsive processor commands...
Checking misc settings...

Total Warnings: 6
Total Errors: 0

Things look okay - No serious problems were detected during the pre-flight check
abrist
Red Shirt
Posts: 8334
Joined: Thu Nov 15, 2012 1:20 pm

Re: Changing localhost in Nagios console to the hostname

Post by abrist »

Was this verification run after the hostname was changed? (or did you change it back to what it was originally?)
Former Nagios employee
"It is turtles. All. The. Way. Down. . . .and maybe an elephant or two."
VI VI VI - The editor of the Beast!
Come to the Dark Side.
esauve
Posts: 3
Joined: Tue Sep 17, 2013 12:51 pm

Re: Changing localhost in Nagios console to the hostname

Post by esauve »

I did change it back but I modified it again (changed the host-name entry in localhost.cfg) and ran nagios -v /etc/nagios/nagios.cfg. Below is the output

[root@cabro1mon0001 ~]# nagios -v /etc/nagios/nagios.cfg

Nagios Core 3.5.0
Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 03-15-2013
License: GPL

Website: http://www.nagios.org
Reading configuration data...
Read main config file okay...
Processing object config file '/etc/nagios/objects/commands.cfg'...
Processing object config file '/etc/nagios/objects/contacts.cfg'...
Processing object config file '/etc/nagios/objects/timeperiods.cfg'...
Processing object config file '/etc/nagios/objects/templates.cfg'...
Processing object config file '/etc/nagios/objects/localhost.cfg'...
Processing object config directory '/etc/nagios/servers'...
Processing object config file '/etc/nagios/servers/clients.cfg'...
Processing object config directory '/etc/nagios/conf.d'...
Error: Could not find any host matching 'localhost' (config file '/etc/nagios/objects/localhost.cfg', starting on line 46)
Error: Could not expand members specified in hostgroup (config file '/etc/nagios/objects/localhost.cfg', starting on line 46)
Error processing object config files!


***> One or more problems was encountered while processing the config files...

Check your configuration file(s) to ensure that they contain valid
directives and data defintions. If you are upgrading from a previous
version of Nagios, you should be aware that some variables/definitions
may have been removed or modified in this version. Make sure to read
the HTML documentation regarding the config files, as well as the
'Whats New' section to find out what has changed.
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: Changing localhost in Nagios console to the hostname

Post by slansing »

You would need to re-add the localhost.cfg file under /directory/path/to/hosts and then re-verify. If the CFG is for a host definition then it must be under the hosts folder, similarly if it is for a service it must be under services and that host must exist.
dadamson
Posts: 1
Joined: Fri Dec 01, 2017 12:18 pm

Re: Changing localhost in Nagios console to the hostname

Post by dadamson »

@esuave

I had the same error messages. I'm new and can't offer expert advice but I can tell you what I did to fix that same error for me on a fresh install.

I edited the localhost.cfg file located for me at /usr/local/nagios/etc/objects/localhost.cfg.

Actually before editing the file I made a copy of the original so that I can always start over with an original configuration file. cp localhost.cfg localhost.cfg_orig

Under the first section "HOST DEFINITION"

define host{
use Linux-server

host_name webServer
alias localhost
address 127.0.0.1
}

The only thing I changed was the host_name line. And I changed it to my local computers hostname which is webServer.

The configuration file has additional definitions through out the remainder of the file. In every definition I made the same change. I only changed the host_name line to my computers hostname.

If I didn't make the change to all of them the configuration would fail. I ran the following command after editing the file to validate the changes:
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

after that I restarted the httpd service and Nagios services:
systemctl stop httpd.service
systemctl stop nagios.service
systemctl start httpd.service
systemctl start nagios.service

After that my host showed up in Nagios as it's actual hostname, webServer instead of localhost. It also got rid of the other errors I was getting:
(No ouput on stdout) stderr: execvp(/usr/local/Nagios/libexec/check_ping, ...) failed. errno is 2: No such file or directory

I installed on CentOS 7.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: Changing localhost in Nagios console to the hostname

Post by tmcdonald »

Thank you for the post, but this thread is over 4 years old and I don't think the OP will be coming back any time soon, so I will be closing this now.
Former Nagios employee
Locked