mclarkson / nagrestconf

Nagios REST Interface
12 stars 5 forks source link

Hard-coded paths to Nagios3; want to change paths to Nagios 4.x #68

Closed dchang0 closed 7 years ago

dchang0 commented 7 years ago

Hi, Mark--

I'm getting these errors on the initial config:

----------------------------------------------------------------------------------------------------
- APPLYING NAGIOS CONFIGURATION (csv2nag -y all)
----------------------------------------------------------------------------------------------------

sudo: no tty present and no askpass program specified

----------------------------------------------------------------------------------------------------
- NAGIOS CONFIGURATION CHECK (nagios -v /etc/nagios/nagios.cfg)
----------------------------------------------------------------------------------------------------

sudo: no tty present and no askpass program specified

CONFIG ERROR

----------------------------------------------------------------------------------------------------
- SCHEDULING NAGIOS RESTART
----------------------------------------------------------------------------------------------------

NAGCTL ERROR: Config error. Nagios restart request not sent.

The path /etc/nagios/nagios.cfg is clearly wrong. It should either be:

/etc/nagios3/nagios.cfg for the Debian/Ubuntu packaged nagios3

or

/usr/local/nagios/etc/nagios.cfg for the built-from-source Nagios 4.x

I have updated the NAG_DIR variable correctly in /etc/nagrestconf/nagctl.conf, but it does not seem to recognize the path. Either that, or it is the sudo error that is preventing the config from working (sudo is indeed installed, and www-data is temporarily given ALL sudo privileges).

dchang0 commented 7 years ago

Looking through the source code for /usr/share/nagrestconf/htdocs/nagrestconf/index.php, I suspect that the /etc/nagios/nagios.cfg is just for display and isn't actually used as the path. In that case, the sudo error is more likely to be causing the problem.

mclarkson commented 7 years ago

nagrestconf_install should have done that. See the function add_sudoers_entry() in https://github.com/mclarkson/nagrestconf/blob/master/SOURCES/nagrestconf-1/scripts/nagrestconf_install. Take a look at that file to see what to add. I'll take a look at my 16.04 installation tomorrow.

dchang0 commented 7 years ago

Hmm. Let me re-run it.

I should probably rename this ticket too, once I confirm the fix.

dchang0 commented 7 years ago

Separate issue: small typo in nagrestconf_install -a

usermod -a -G nagiocmd www-data
usermod: group 'nagiocmd' does not exist

Should be nagioscmd. Not sure if worth opening another ticket.

dchang0 commented 7 years ago

Okay, I can get further now after re-running nagrestconf_install.

Next error:


----------------------------------------------------------------------------------------------------
- APPLYING NAGIOS CONFIGURATION (csv2nag -y all)
----------------------------------------------------------------------------------------------------

Creating hosts file local-nodes/mgmt/localhost.cfg
Creating hostgroups file local_hostgroups.cfg
Adding services to local-nodes/mgmt/localhost.cfg
Creating servicegroups file local_servicegroups.cfg
Creating hosttemplates file local_hosttemplates.cfg
Creating servicetemplates file local_servicetemplates.cfg
Creating timeperiods file local_timeperiods.cfg
Creating commands file local_commands.cfg
Creating contacts file local_contacts.cfg
WARNING: setup/local_servicedeps.setup not found. Skipping...
WARNING: setup/local_hostdeps.setup not found. Skipping...
WARNING: setup/local_serviceesc.setup not found. Skipping...
WARNING: setup/local_hostesc.setup not found. Skipping...
WARNING: setup/local_serviceextinfo.setup not found. Skipping...
WARNING: setup/local_hostextinfo.setup not found. Skipping...

----------------------------------------------------------------------------------------------------
- NAGIOS CONFIGURATION CHECK (nagios -v /etc/nagios/nagios.cfg)
----------------------------------------------------------------------------------------------------

Nagios Core 4.3.1
Copyright (c) 2009-present Nagios Core Development Team and Community Contributors
Copyright (c) 1999-2009 Ethan Galstad
Last Modified: 02-23-2017
License: GPL

Website: https://www.nagios.org
Reading configuration data...
Error in configuration file '/usr/local/nagios/etc/nagios.cfg' - Line 1357 (NULL value)
   Error processing main config file!

CONFIG ERROR

----------------------------------------------------------------------------------------------------
- SCHEDULING NAGIOS RESTART
----------------------------------------------------------------------------------------------------

NAGCTL ERROR: Config error. Nagios restart request not sent.
dchang0 commented 7 years ago

I do have the "missing" .setup files at this path:

/usr/local/nagios/etc/objects/local/setup

These files were successfully created:

root@it01:/usr/local/nagios/etc/objects# find 
.
./local
./local/local-nodes
./local/local-nodes/mgmt
./local/local-nodes/mgmt/localhost.cfg
./local/local_hostgroups.cfg
./local/local_commands.cfg
./local/local_servicegroups.cfg
./local/local_hosttemplates.cfg
./local/setup
./local/setup/local_contacts.setup
./local/setup/local_servicetemplates.setup
./local/setup/local_servicegroups.setup
./local/setup/local_services.setup
./local/setup/local_commands.setup
./local/setup/local_hostgroups.setup
./local/setup/local_hosts.setup
./local/setup/local_servicesets.setup
./local/setup/local_hosttemplates.setup
./local/setup/local_servicegroups.auto.setup
./local/setup/local_hostgroups.auto.setup
./local/setup/local_timeperiods.setup
./local/setup/local_contactgroups.setup
./local/local_contacts.cfg
./local/local_timeperiods.cfg
./local/local_servicetemplates.cfg

Maybe this ticket should keep the title about hard-coded paths after all, LOL.

This is what is at line 1357 in the current /usr/local/nagios/etc/nagios.cfg file:

## Next line added by nagrestconf
<SERVICE_LINE_CFG_ENTRY>

The is line 1357. The comment is line 1356.

I found this file:

/usr/local/nagios/etc/nagios.cfg.nagrestconf-saved

I copied it onto nagios.cfg, overwriting it, and then restarted Nagios 4.x manually. It seems to be working fine, so I now have the initial demonstration config working.

Thanks for the quick response, by the way.

dchang0 commented 7 years ago

It appears that the last issue I had is the same is Issue #52.

mclarkson commented 7 years ago

'nagiocmd' is correct :)

This is getting messy! I would have no faith after completing all of this.

You really need to try this in virtualbox to see how it should be - to have a system to compare to.

Install virtualbox and vagrant then:

cd
mkdir xenial
cd xenial
vagrant init ubuntu/xenial64
vagrant up --provider virtualbox
vagrant ssh -- -L 8888:127.0.0.1:80

Follow the installation instructions /exactly/ except, to test the UI connect to http://127.0.0.1:8888/nagrestconf (or nagios3) from your desktop.

Use the vagrant mount to copy files into the VM.

Sorry. You're gonna have to do it 'cos this is too messy!

dchang0 commented 7 years ago

Yeah, I think I'm getting too ambitious using PHP 7.0 AND Nagios 4.3.1. Far out of your intended target.

Interesting. I'm used to using nagcmd per the Nagios instructions at:

https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/4/en/quickstart-ubuntu.html

I'm guessing this is gonna cause problems too, if nagrestconf expects it to be called nagiocmd.

I'll keep hacking away at this and kinda document my progress via these issues.

Ran into another problem worthy of a ticket, LOL. Sorry about that.

dchang0 commented 7 years ago

I think you can close this ticket. I got past the major roadblocks and essentially duplicated Issue 52.

Of course, my installation of nagrestconf is still broken, but this particular issue is probably solved.

mclarkson commented 7 years ago

I did not set nagiocmd, the distro did that. It's nearly always best to use distribution packages where possible (unless you need bleeding edge), especially for production boxes. Nagios recommend things their way, distros have different ideas and care more about the integration of the package into the OS. Centos 7 uses nagios4 but not 4.3.x series so that would also not be an option for you unfortunately. Personally I would hunt the internet for debs that were based on nagios 3 (so they will have nagiocmd!), or build a nagios4 for ubuntu based on the nagios3 deb (that's what I did for nagios3 when only nagios2 was available on centos/redhat). Then, for upgrades you rebuild your deb and it's much nicer - especially if you have distributed nagios over many boxes.

I still don't trust your installation and would not recommend you use it for production machines. For testing it's fine :)

EDIT: I tried the install again from scratch and it works, but nagiocmd does not exist on ubuntu so a failure is shown when running 'sudo nagrestconf_install -a' but everything still works OK since instead of nagiocmd it uses www-data.

dchang0 commented 7 years ago

Thanks. We decided to pull it from our production box on the same basis. I'll play around with nagrestconf and Nagios 4.3.1 built-from-source on a dev box for a while and see how far I can get. It does sound like it can be made to work, based on your testing.