NagiosEnterprises / nagioscore

Nagios Core
GNU General Public License v2.0
1.48k stars 440 forks source link

Fix inconsistent links for 'View {Trends,Alert Histogram} For This {Host,Service}' #969

Open mfoliveira opened 2 weeks ago

mfoliveira commented 2 weeks ago

These links are working or broken depending on the page they are clicked, if configure option cgiurl has cgi-bin/ not under nagios/ HTML root:

They fail if clicked from Current Status > Hosts / Services.
They work if clicked from Reports > Trends > Report Type: Host / Service.

This happens because TRENDS_CGI and HISTOGRAM_CGI for the HTML pages are defined as RELATIVE PATHs (../*.html), but they may be clicked from pages at DIFFERENT PATHs (e.g., /cgi-bin/nagios/*.cgi -- note it would work for /nagios/cgi-bin/*.cgi, as nagios/ is HTML root).

This affects Debian/Ubuntu, which use --with-cgiurl=/cgi-bin/nagios4.

Fix this by using ABSOLUTE PATHs to the HTML root, where trends.html and histogram.html are located.

Tests:

This has been tested with 4.5.2, as 4.5.3 removed these .html files, on Ubuntu Oracular (to be 24.10) with a web browser.

The CGI binaries' strings output have been compared before/after, and the only changes (other than build-time noise) are indeed the path changes to {trends,histogram}.html files. Some snippets:

    ./configure \
      --with-httpd-conf=/etc/apache2/sites-enabled \
      --with-htmurl=/nagios4 \
      --with-cgiurl=/cgi-bin/nagios4 `# instead of /nagios4/cgi-bin` \
      --with-cgibindir=/usr/lib/cgi-bin/nagios4
    make -j(nproc) all

    Original: $ strings ./cgi/*.cgi >/tmp/nagios-4.5.2-cgi-old.strings
    (Patch/Clean/Build)
    Modified: $ strings ./cgi/*.cgi >/tmp/nagios-4.5.2-cgi-new.strings
    Checking: $ diff -U0 /tmp/nagios-4.5.2-cgi-{old,new}.strings
    ...
    @@ -1604 +1605 @@
    -18:33:07
    +18:46:58
    @@ -7859 +7860 @@
    -../trends.html
    +/nagios4/trends.html
    @@ -7884 +7885 @@
    -../histogram.html
    +/nagios4/histogram.html
    ...
    @@ -9145 +9146 @@
    -?Host Availabilitlability Report
    +Host Availabilitlability Report
    @@ -23503 +23504 @@
    -6{L5
    +3+tk
    @@ -24564 +24565 @@
    -o%ev
    +o%uv
    @@ -25505,2 +25506,2 @@
    -../trends.html
    -../histogram.html
    +/nagios4/trends.html
    +/nagios4/histogram.html
    ...
mfoliveira commented 2 weeks ago

Build and Test steps.

LXD container / nagios-core / nagios-plugins:

lxc launch ubuntu-daily:oracular nagios-upstream
lxc exec nagios-upstream -- su - ubuntu

# Reference:
# https://support.nagios.com/kb/article/nagios-core-installing-nagios-core-from-source-96.html#Ubuntu

sudo apt install -y \
  autoconf gcc libc6 \
  make wget unzip \
  apache2 php libapache2-mod-php8.3 \
  libgd-dev openssl libssl-dev

wget https://github.com/NagiosEnterprises/nagioscore/releases/download/nagios-4.5.2/nagios-4.5.2.tar.gz
tar xf nagios-4.5.2.tar.gz
cd nagios-4.5.2/

./configure \
  --with-httpd-conf=/etc/apache2/sites-enabled \
  --with-htmurl=/nagios4 \
  --with-cgiurl=/cgi-bin/nagios4 `# instead of /nagios4/cgi-bin` \
  --with-cgibindir=/usr/lib/cgi-bin/nagios4

make -j$(nproc) all

sudo make install-groups-users
sudo usermod -a -G nagios www-data
sudo make install
sudo make install-daemoninit
sudo make install-commandmode
sudo make install-config
sudo make install-webconf
sudo a2enmod rewrite
sudo a2enmod cgi

sudo htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin # nagiospass / nagiospass
sudo sed '/^use_authentication=/ s/=1/=0/' -i /usr/local/nagios/etc/cgi.cfg

sudo systemctl restart apache2.service
sudo systemctl start nagios.service

sudo apt install -y \
  libmcrypt-dev bc dc \
  gawk build-essential \
  snmp libnet-snmp-perl gettext

cd
wget https://github.com/nagios-plugins/nagios-plugins/releases/download/release-2.4.10/nagios-plugins-2.4.10.tar.gz
tar xf nagios-plugins-2.4.10.tar.gz./to 
cd nagios-plugins-2.4.10/

./configure \
  --with-cgiurl=/cgi-bin/nagios4
make -j$(nproc)
sudo make install

sudo systemctl restart nagios.service

Browser-based testing:

<LXD>$ ip -4 a l type veth | awk '/inet/ { print $2 }'
10.191.59.8/24

<HOST>$ firefox http://10.191.59.8/nagios4

Before:

Check that links are broken from the Current Status section, but are working from the Reports > Trends section.

Apply Patch/Reinstall:

make -j$(nproc) clean
make -j$(nproc) all
sudo make install

After:

Check that links are now working from the Current Status section, and are still working from the Reports > Trends section.

mfoliveira commented 1 week ago

Hi @sawolf,

Sorry to bother. Could you please review this when you have a chance?

I'm not familiar with the project timelines, so please excuse this ping if it is too early. Thanks!

sawolf commented 5 days ago

Hi @mfoliveira, thanks for the patch! The code looks reasonable to me.

@tsadpbb can you test this and include it in the next release if it's good?