mclarkson / nagrestconf

Nagios REST Interface
12 stars 5 forks source link

Support for php 7 #66

Closed riknykn closed 7 years ago

riknykn commented 7 years ago

Ubuntu package requires php version 5.3, which is not supported (not even included in the repositories) in the latest LTS version 16.04. Again nagios itself requires php 7 on Ubuntu 16.04, which makes installation of nagios and nagrestconf pretty much impossible on Ubuntu versions 16+. Please, add support support for php7.

mclarkson commented 7 years ago

Many thanks for reporting this. I will certainly look into it ASAP.

dchang0 commented 7 years ago

I'm also running Ubuntu 16.04 and PHP 7.0.

Follow up on Mark's idea to try using dpkg --ignore-depends:

dpkg -i --ignore-depends=php5 --ignore-depends=nagios3 --ignore-depends=php5-curl nagrestconf_1.174.5_all.deb Selecting previously unselected package nagrestconf. (Reading database ... 103983 files and directories currently installed.) Preparing to unpack nagrestconf_1.174.5_all.deb ... Unpacking nagrestconf (1.174.5) ... Setting up nagrestconf (1.174.5) ... ERROR: Module php5 does not exist! dpkg: error processing package nagrestconf (--install): subprocess installed post-installation script returned error exit status 1 Processing triggers for man-db (2.7.5-1) ... Errors were encountered while processing: nagrestconf

(I built Nagios 4.3.2 from source code, hence the --ignore-depends=nagios3.)

To check the PHP code to see if it really is PHP 7.0 compatible, one idea is try this compatibility checker: https://github.com/sstalle/php7cc

dchang0 commented 7 years ago

I just ran php7cc on the source code for nagrestconf from Github, and it seems that it passes the PHP 7.0 compatibility check, so I figure once we get rid of this annoying php5 requirement, it will install and run just fine with PHP 7.0.

How would one manually-install nagrestconf from source code? It looks like it's just a matter of copying files into specific paths.

mclarkson commented 7 years ago

Ok, thanks for trying that, and nice one for running php7cc!

So, it might be better to build from source but you'll need to install debian stretch, maybe in lxc. I just installed ununtu xenial in virtualbox using vagrant.

So when in Ubuntu 16.04 (Xenial):

sudo apt install lxc
# I needed --no-validate behind a proxy:
sudo lxc-create --template download --name u1 -- --no-validate --dist debian --release stretch --arch amd64
sudo lxc-start --name u1 --daemon
sudo lxc-attach --name u1

We now have a stretch console under ubuntu Lets clone nagrestconf, modify the php version, then build a .deb Continuing our previous session:

su -
apt install git build-essential devscripts debhelper debootstrap
git clone https://github.com/mclarkson/nagrestconf.git
cd ~/nagrestconf/SOURCES/
rm -f *.deb
cd ~/nagrestconf/SOURCES/nagrestconf-1/
cp -a debian.jessie/ debian.stretch
cd debian.stretch/
# Edit the control file, replacing php5
sed -i 's/php5 [^,]*/php/;s/php5/php/;' control
# Edit postinst too
sed -i 's/php5/php7.0/' postinst
cd ..
ln -s debian.stretch/ debian
debuild -I -i -us -uc
exit
exit

Those final two exits brings us back out to xenial prompt. Now gdebi the main .deb:

sudo apt install gdebi-core
sudo nsenter -m -t `pidof lxcfs`
gdebi /var/lib/lxc/u1/rootfs/root/nagrestconf/SOURCES/nagrestconf_1.174.7_all.deb
exit

And then continue with the install instructions after the gdebi line.

I have my fingers crossed!

dchang0 commented 7 years ago

Thanks for the directions. I get this error here: root@u1:/# cd ~/nagrestconf/SOURCES/nagrestconf-1/ bash: cd: /home/sysadmin/nagrestconf/SOURCES/nagrestconf-1/: No such file or directory root@u1:/# cp -a debian.jessie/ debian.stretch cp: cannot stat 'debian.jessie/': No such file or directory I'll see if I can get around it.

UPDATE: looks like I can get around it by removing the ~/ and using: cd nagrestconf/SOURCES/nagrestconf-1

All the remaining steps through the two exits worked fine.

Then this error: gdebi /var/lib/lxc/u1/rootfs/root/nagrestconf/SOURCES/nagrestconf_1.174.7_all.deb gdebi error, file not found: /var/lib/lxc/u1/rootfs/root/nagrestconf/SOURCES/nagrestconf_1.174.7_all.deb

Correct path appears to be this: /var/lib/lxc/u1/rootfs/nagrestconf/SOURCES (Leave out the root after rootfs.)

The package does now get past the requirement for php5. However, it hits the screen where it says:

Configuring nagios3-cgi

I don't have nagios3-cgi (built Nagios 4 from source). This may not be a problem. I will try to get past it and update here.

UPDATE 2:

I got past the Configuring nagios3-cgi screen by providing the nagiosadmin password. The process looked like it was doing fine until this error:

Creating config file /etc/nagios-plugins/config/snmp.cfg with new version Setting up monitoring-plugins (2.1.2-2ubuntu2) ... Setting up nagios-plugins (2.1.2-2ubuntu2) ... Processing triggers for libc-bin (2.23-0ubuntu7) ... Processing triggers for systemd (229-4ubuntu17) ... Processing triggers for ureadahead (0.100.0-19) ... Processing triggers for php7.0-fpm (7.0.15-0ubuntu0.16.04.4) ... Selecting previously unselected package nagrestconf. (Reading database ... 108253 files and directories currently installed.) Preparing to unpack nagrestconf_1.174.7_all.deb ... Unpacking nagrestconf (1.174.7) ... Setting up nagrestconf (1.174.7) ... ERROR: Module php7.0 does not exist! dpkg: error processing package nagrestconf (--install): subprocess installed post-installation script returned error exit status 1 Processing triggers for man-db (2.7.5-1) ... Errors were encountered while processing: nagrestconf

php7.0 is indeed installed: ii php7.0 7.0.15-0ubuntu0.16.04.4 all server-side, HTML-embedded scripting language (metapackage) I guess we have to go back and re-build the package. Mark, is this "module" something inside of the nagrestconf package and not the actual php7.0 package from the Debian repositories?

mclarkson commented 7 years ago

You needed to do 'su -', with the minus, straight after the 'lxc attach'. The second problem was also because you didn't do the 'su -' :) You don't have php7.0 module because you probably didn't use gdebi, but instead did the dpkg with no deps so also you won't have apache and other things.

I followed the above instructions exactly, just copy/pasted, to create the debs and I've uploaded to sourceforge and created Ubuntu Xenial instructions at: http://nagrestconf.smorg.co.uk/installguides/ubuntu_xenial.php

All seems to work fine for me, surprisingly! I restored the sample backup file (from the 'Create an initial configuration' section) and after pressing Apply Configuration nagios3 started up automatically and things started going green.

In your case, follow the xenial installation instructions exactly and verify it's working. Then install nagios4 and modify the files in /etc/nagrestconf to match the new installation.

dchang0 commented 7 years ago

Ah yes, I did leave out the su - (was already sudo -s as root). I did use gdebi though and not deb... This is what I used:

sudo apt install gdebi-core
sudo nsenter -m -t `pidof lxcfs`
gdebi /var/lib/lxc/u1/rootfs/root/nagrestconf/SOURCES/nagrestconf_1.174.7_all.deb
exit

I'll give it another try and see if it happens again.

UPDATE:

Including the su - fixed all the errors all the way down. The "root" after "rootfs" worked fine. I could simply cut and paste your code exactly, and it worked.

mclarkson commented 7 years ago

gdebi should have ended up installing the following php packages:

libapache2-mod-php     server-side, HTML-embedded scripting language (Apache 2 module) (default)
libapache2-mod-php7.0  server-side, HTML-embedded scripting language (Apache 2 module)
php                    server-side, HTML-embedded scripting language (default)
php-common             Common files for PHP packages
php-curl               CURL module for PHP [default]
php7.0                 server-side, HTML-embedded scripting language (metapackage)
php7.0-cli             command-line interpreter for the PHP scripting language
php7.0-common          documentation, examples and common module for PHP
php7.0-curl            CURL module for PHP
php7.0-json            JSON module for PHP
php7.0-opcache         Zend OpCache module for PHP
php7.0-readline        readline module for PHP
dchang0 commented 7 years ago

I tried it again, cutting and pasting your code exactly and got the same error.

gdebi /var/lib/lxc/u1/rootfs/root/nagrestconf/SOURCES/nagrestconf_1.174.7_all.deb
Reading package lists... Done
Building dependency tree        
Reading state information... Done
Reading state information... Done

REST interface and configuration GUI for Nagios.
 Nagrestconf:
 .
  * allows Nagios to be configured using a REST api.
  * allows the server to be restarted using the REST api.
  * provides a Web GUI for configuring built on the REST api.
 .
 It can be useful for:
 .
  * Bulk loading
  * Bulk editing
  * Automation
  * Catching common configuration mistakes
Do you want to install the software package? [y/N]:y
(Reading database ... 108374 files and directories currently installed.)
Preparing to unpack .../nagrestconf_1.174.7_all.deb ...
Unpacking nagrestconf (1.174.7) over (1.174.7) ...
Setting up nagrestconf (1.174.7) ...
ERROR: Module php7.0 does not exist!
dpkg: error processing package nagrestconf (--install):
 subprocess installed post-installation script returned error exit status 1
Processing triggers for man-db (2.7.5-1) ...
Errors were encountered while processing:
 nagrestconf
dchang0 commented 7 years ago

These were not installed: libapache2-mod-php
libapache2-mod-php7.0

Installed just now and trying again. Seems to work and get all the way to the end now. I'm not sure why libapache2-mod-php was not installed.

At this point, it appears that I have a successful installation of nagrestconf and merely need to customize it to fit my Nagios 4.x installation. Thanks!

dchang0 commented 7 years ago

Okay, I just installed the newly-built package on our production server. It did work, although the prerequisite of nagios3 means I have two installations of Nagios on my server. I will leave nagios3, but it would be nice if future versions of nagrestconf could be told to ignore the nagios3 requirement (as well as any other packages not strictly required for nagrestconf to work).

I've configured the files in /etc/nagrestconf to point to the Nagios 4.x install and it seems to work.

Thanks for the help, Mark!!