-
Notifications
You must be signed in to change notification settings - Fork 74
Adagios 1.6.4 on CentOS 7.8 with Nagios 4.4.5
This chapter shows how to install adagios on Centos 7.6.
- In this wiki, We use an example Nagios Server, monitor01.test.lan(192.168.1.16) with Nagios 4.3.4 and pnp4nagios already installed.
- acl,selinux and firewall are disabled.
- CentOS 7.8 OS info.
-bash-4.2$ uname -a && cat /etc/redhat-release;date
Linux monitor01 3.10.0-1127.18.2.el7.x86_64 #1 SMP Sun Jul 26 15:27:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
CentOS Linux release 7.8.2003 (Core)
Tue Aug 18 04:18:42 CDT 2020
-bash-4.2$
- nagios rpm installed.
-bash-4.2$ rpm -qa |grep nagios-4.4
nagios-4.4.5-7.el7.x86_64
-bash-4.2$
- Django installed
-bash-4.2$ rpm -qa |grep django
python2-django16-1.6.11.7-5.el7.noarch
python-django16-bash-completion-1.6.11.7-5.el7.noarch
-bash-4.2$
- pnp4 nagios installed.
-bash-4.2$ rpm -qa |grep pnp4nagios
pnp4nagios-0.6.25-1.el7.x86_64
-bash-4.2$
rpm -ihv http://opensource.is/repo/ok-release.rpm
yum update -y ok-release
# check the ok repo.
cat /etc/yum.repos.d/ok.repo
# we should see following
[ok]
name=Opin Kerfi Public Repo - $basearch
baseurl=http://opensource.is/repo/rhel$releasever/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
[ok-testing]
name=Opin Kerfi Public Repo - Testing - $basearch
baseurl=http://opensource.is/repo/testing/rhel$releasever/$basearch
failovermethod=priority
enabled=0
gpgcheck=0
- Make sure /etc/init.d/nagios {stop|start|status|reload} works by adding following nagios sysvinit file.
adagios 1.6.3 still expect /etc/init.d/nagios to control nagios 4.3.4 on centos 7.
- /etc/init.d
[root@nagios03 init.d]# ls -lrt
total 60
-rwxr-xr-x 1 root root 1630 Jun 8 2015 npcd
-rwxr-xr-x 1 root root 1422 Dec 18 2015 atieventsd
-rwxr-xr-x 1 root root 7293 May 3 2017 network
-rwxr-xr-x 1 root root 4334 May 3 2017 netconsole
-rw-r--r-- 1 root root 17500 May 3 2017 functions
-rw-r--r-- 1 root root 1160 Jan 25 10:52 README
-rwxr-xr-x 1 root root 9911 Feb 4 08:26 nagios
[root@nagios01 init.d]#
- /etc/init.d/nagios
[root@nagios01 ~]# cat /etc/init.d/nagios
#!/bin/sh
#
# chkconfig: 345 99 01
# description: Nagios network monitor
# processname: nagios
# pidfile: /var/run/nagios/nagios.pid
# File : nagios
#
# Author : Jorge Sanchez Aymar ([email protected])
#
# Changelog :
# 2018-02-04 T.J. Yang <[email protected]>
# - update the variables and path for 4.3.4 nagios rpm on CentOS 7.4.
# 1999-07-09 Karl DeBisschop <[email protected]>
# - setup for autoconf
# - add reload function
# 1999-08-06 Ethan Galstad <[email protected]>
# - Added configuration info for use with RedHat's chkconfig tool
# per Fran Boon's suggestion
# 1999-08-13 Jim Popovitch <[email protected]>
# - added variable for nagios/var directory
# - cd into nagios/var directory before creating tmp files on startup
# 1999-08-16 Ethan Galstad <[email protected]>
# - Added test for rc.d directory as suggested by Karl DeBisschop
# 2000-07-23 Karl DeBisschop <[email protected]>
# - Clean out redhat macros and other dependencies
# 2003-01-11 Ethan Galstad <[email protected]>
# - Updated su syntax (Gary Miller)
#
# Description: Starts and stops the Nagios monitor
# used to provide network services status.
#
### BEGIN INIT INFO
# Provides: nagios
# Required-Start: $local_fs $syslog $network
# Required-Stop: $local_fs $syslog $network
# Short-Description: Starts and stops the Nagios monitoring server
# Description: Starts and stops the Nagios monitoring server
### END INIT INFO
# Our install-time configuration.
prefix=/usr
exec_prefix=${prefix}
NagiosBin=${exec_prefix}/sbin/nagios
NagiosCfgFile=/etc/nagios/nagios.cfg
#
NagiosCfgtestFile=${prefix}/var/nagios.configtest
NagiosStatusFile=${prefix}/var/status.dat
NagiosLockDir=/usr/local/nagiosxi/var/subsys
#NagiosLockDir=/var/lock/subsys
#
NagiosRunFile=/var/run/nagios/nagios.pid
NagiosRetentionFile=/var/log/nagios/retention.dat
NagiosCommandFile=/var/spool/nagios/cmd/nagios.cmd
NagiosVarDir=/var/nagios
NagiosLockFile=nagios
NagiosCGIDir=/usr/lib64/nagios/cgi-bin
NagiosUser=nagios
NagiosGroup=nagios
checkconfig="true"
# Source function library
# Some *nix do not have an rc.d directory, so do a test first
if [ -f /etc/rc.d/init.d/functions ]; then
. /etc/rc.d/init.d/functions
elif [ -f /etc/init.d/functions ]; then
. /etc/init.d/functions
elif [ -f /lib/lsb/init-functions ]; then
. /lib/lsb/init-functions
fi
# Load any extra environment variables for Nagios and its plugins.
if test -f /etc/sysconfig/nagios; then
. /etc/sysconfig/nagios
fi
# Automate addition of RAMDISK based on environment variables
USE_RAMDISK=${USE_RAMDISK:-0}
if test "$USE_RAMDISK" -ne 0 && test "$RAMDISK_SIZE"X != "X"; then
ramdisk=`mount |grep "${RAMDISK_DIR} type tmpfs"`
if [ "$ramdisk"X == "X" ]; then
mkdir -p -m 0755 ${RAMDISK_DIR}
mount -t tmpfs -o size=${RAMDISK_SIZE}m tmpfs ${RAMDISK_DIR}
mkdir -p -m 0755 ${RAMDISK_DIR}/checkresults
chown -R $NagiosUser:$NagiosGroup ${RAMDISK_DIR}
fi
fi
check_config ()
{
TMPFILE=$(mktemp /tmp/.configtest.XXXXXXXX)
$NagiosBin -vp $NagiosCfgFile > "$TMPFILE"
WARN=`grep ^"Total Warnings:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`
ERR=`grep ^"Total Errors:" "$TMPFILE" |awk -F: '{print \$2}' |sed s/' '//g`
if test "$WARN" = "0" && test "${ERR}" = "0"; then
echo "OK - Configuration check verified" > $NagiosCfgtestFile
chmod 0644 $NagiosCfgtestFile
chown $NagiosUser:$NagiosGroup $NagiosCfgtestFile
/bin/rm "$TMPFILE"
return 0
elif test "${ERR}" = "0"; then
# Write the errors to a file we can have a script watching for.
echo "WARNING: Warnings in config files - see log for details: $NagiosCfgtestFile" > $NagiosCfgtestFile
egrep -i "(^warning|^error)" "$TMPFILE" >> $NagiosCfgtestFile
chmod 0644 $NagiosCfgtestFile
chown $NagiosUser:$NagiosGroup $NagiosCfgtestFile
/bin/rm "$TMPFILE"
return 0
else
# Write the errors to a file we can have a script watching for.
echo "ERROR: Errors in config files - see log for details: $NagiosCfgtestFile" > $NagiosCfgtestFile
egrep -i "(^warning|^error)" "$TMPFILE" >> $NagiosCfgtestFile
chmod 0644 $NagiosCfgtestFile
chown $NagiosUser:$NagiosGroup $NagiosCfgtestFile
cat "$TMPFILE"
exit 8
fi
}
status_nagios ()
{
if test -x $NagiosCGI/daemonchk.cgi; then
if $NagiosCGI/daemonchk.cgi -l $NagiosRunFile > /dev/null 2>&1; then return 0; fi
else
if ps -p $NagiosPID > /dev/null 2>&1; then return 0; fi
fi
return 1
}
printstatus_nagios ()
{
if status_nagios; then
echo "nagios (pid $NagiosPID) is running..."
else
echo "nagios is not running"
exit 3
fi
}
killproc_nagios ()
{
kill -s "$1" $NagiosPID
}
pid_nagios ()
{
if test ! -f $NagiosRunFile; then
echo "No lock file found in $NagiosRunFile"
exit 3
fi
NagiosPID=`head -n 1 $NagiosRunFile`
}
# Check that nagios exists.
if [ ! -f $NagiosBin ]; then
echo "Executable file $NagiosBin not found. Exiting."
exit 1
fi
# Check that nagios.cfg exists.
if [ ! -f $NagiosCfgFile ]; then
echo "Configuration file $NagiosCfgFile not found. Exiting."
exit 1
fi
# See how we were called.
case "$1" in
start)
echo -n "Starting nagios:"
if test "$checkconfig" = "true"; then
check_config
# check_config exits on configuration errors.
fi
if test -f $NagiosRunFile; then
NagiosPID=`head -n 1 $NagiosRunFile`
if status_nagios; then
echo " another instance of nagios is already running."
exit 0
fi
fi
touch $NagiosVarDir/nagios.log $NagiosRetentionFile
rm -f $NagiosCommandFile
touch $NagiosRunFile
chown $NagiosUser:$NagiosGroup $NagiosRunFile $NagiosVarDir/nagios.log $NagiosRetentionFile
chmod g+r $NagiosVarDir/nagios.log
USER=$NagiosUser G_BROKEN_FILENAMES=1 SSH_TTY=/dev/pts/0 $NagiosBin -d $NagiosCfgFile
if [ -d $NagiosLockDir ]; then touch $NagiosLockDir/$NagiosLockFile; fi
service snmptt restart &>/dev/null ||:
echo " done."
;;
stop)
echo -n "Stopping nagios:"
pid_nagios
killproc_nagios TERM
# now we have to wait for nagios to exit and remove its
# own NagiosRunFile, otherwise a following "start" could
# happen, and then the exiting nagios will remove the
# new NagiosRunFile, allowing multiple nagios daemons
# to (sooner or later) run - John Sellens
#echo -n 'Waiting for nagios to exit .'
for i in 1 2 3 4 5 6 7 8 9 10 ; do
if status_nagios > /dev/null; then
echo -n '.'
sleep 1
else
break
fi
done
if status_nagios > /dev/null; then
echo ''
echo 'Warning - nagios did not exit in a timely manner'
else
echo ' done.'
fi
rm -f $NagiosStatusFile $NagiosRunFile $NagiosLockDir/$NagiosLockFile $NagiosCommandFile
;;
status)
pid_nagios
printstatus_nagios
;;
checkconfig)
if test "$checkconfig" = "true"; then
printf "Running configuration check...\n"
check_config
fi
if [ $? -eq 0 ]; then
echo " OK."
else
echo " CONFIG ERROR! Check your Nagios configuration."
exit 1
fi
;;
restart)
if test "$checkconfig" = "true"; then
printf "Running configuration check...\n"
check_config
fi
$0 stop
$0 start
;;
reload|force-reload)
if test "$checkconfig" = "true"; then
printf "Running configuration check...\n"
check_config
fi
if test ! -f $NagiosRunFile; then
$0 start
else
pid_nagios
if status_nagios > /dev/null; then
printf "Reloading nagios configuration...\n"
killproc_nagios HUP
echo "done"
else
$0 stop
$0 start
fi
fi
;;
configtest)
$NagiosBin -vp $NagiosCfgFile
;;
*)
echo "Usage: nagios {start|stop|restart|reload|force-reload|status|checkconfig|configtest}"
exit 1
;;
esac
# End of this script
yum install -y epel-release
# We should see following two files.
/etc/yum.repos.d/epel.repo
/etc/yum.repos.d/epel-testing.repo
As of 02/02/2018, Nagios 4.3.4 is available on EPEL for CentOS.
[root@nagios01 ~]# rpm -qi nagios-4.3.4-3.el7.x86_64
Name : nagios
Version : 4.3.4
Release : 3.el7
Architecture: x86_64
Install Date: Wed 13 Dec 2017 02:36:49 PM CST
Group : Applications/System
Size : 9950932
License : GPLv2
Signature : RSA/SHA256, Mon 02 Oct 2017 02:11:26 PM CDT, Key ID 6a2faea2352c64e5
Source RPM : nagios-4.3.4-3.el7.src.rpm
Build Date : Tue 19 Sep 2017 08:13:06 PM CDT
Build Host : buildvm-13.phx2.fedoraproject.org
Relocations : (not relocatable)
Packager : Fedora Project
Vendor : Fedora Project
URL : https://www.nagios.org/projects/nagios-core/
Summary : Host/service/network monitoring program
Description :
Nagios is a program that will monitor hosts and services on your
network. It has the ability to send email or page alerts when a
problem arises and when a problem is resolved. Nagios is written
in C and is designed to run under Linux (and some other *NIX
variants) as a background process, intermittently running checks
on various services that you specify.
<snipped>
[root@nagios01 ~]#
If you don't know how to configure SElinux, put it in permissive mode:
sed -i "s/SELINUX=enforcing/SELINUX=permissive/" /etc/sysconfig/selinux
setenforce 0
systemctl stop firewalld && systemctl disable firewalld
sudo rpm -e okconfig adagios pynag-examples pynag naemon-livestatus
rm -rf /etc/nagios/okconfig/
# as root
cd /etc/nagios
yum --enablerepo=ok-testing install -y \
git adagios okconfig pynag pynag-examples python-setuptools check-mk-livestatus
<snipped>
Dependency Installed:
mod_wsgi.x86_64 0:3.4-12.el7_0
nagios-okplugin-apc.noarch 0:2.1.2-1.git.0.03f7389.el7.centos
nagios-okplugin-brocade.x86_64 0:0.0.5-1.git.0.09dcc39.el7.centos
nagios-okplugin-check_disks.noarch 0:1.0.7-1.git.0.f986b73.el7.centos
nagios-okplugin-check_time.x86_64 0:1.0.3-1.git.0.5f604b8.el7.centos
nagios-okplugin-mailblacklist.noarch 0:1.1-1.git.0.e9222eb.el7.centos
<snipped>
winexe.x86_64 0:1.01-1.git.11.d48449a
Complete!
[root@nagios01 ~]#
find /usr/share/okconfig -type f -exec perl -pi -e 's!normal_check_interval!check_interval!' {} \;
find /usr/share/okconfig -type f -exec perl -pi -e 's!retry_check_interval!retry_interval!' {} \;
- Become nagios user
sudo su - nagios
cd /etc/nagios/servers
- Verify okconfig
okconfig verify
-bash-4.2$ okconfig verify
Okconfig verification
---------------------
* destination_directory /etc/nagios/okconfig is writable ...success
* Main configuration file /etc/nagios/nagios.cfg is readable ...success
* template_directory /usr/share/okconfig/templates exists ...success
-bash-4.2$
[me@nagios03t ~]$ okconfig
Usage: okconfig <command> [arguments]
Common okconfig commands:
addhost Add a new host
addtemplate Add a new template to existing host
addgroup Add a new host/contact/service group
addcontact Add a new contact
addservice Add a service check to host
removehost Delete a host
listtemplates List all available templates
listhosts List all hosts
listhost List a single host
init Initialize nagios to use okconfig
install Install an agent on a remote server
upgrade Runs migration routines in case of okconfig upgrades
verify Verifies current okconfig installation
For help on specific command type:
okconfig <command> --help
Examples:
okconfig addgroup linuxservers --alias "Example Linux Servers"
okconfig addhost <host_name> --template linux --address 127.0.0.1 --group linuxservers
okconfig addtemplate <host_name> --template oracle
okconfig: error: No command specified
[me@nagios03t ~]$
Now all the packages have been installed, and we need to do a little bit of configuration before we start doing awesome monitoring. Lets make sure adagios can write to nagios configuration files, and that it is a valid git repo so we have audit trail
sudo chown -R nagios:nagios /etc/nagios
cd /etc/nagios/
git init
git config user.name "yourname"
git config user.email "[email protected]"
git add *
git commit -m "Initial commit"
chown -R nagios:nagios /etc/nagios/* /etc/nagios/.git
# Run following if you want to have more secure control of files.
# setfacl -R -m group:nagios:rwx /etc/nagios/
# setfacl -R -m d:group:nagios:rwx /etc/nagios/
By default objects created by adagios will go to /etc/nagios/adagios so make sure that this directory exists and nagios.cfg contains a reference to this directory.
mkdir -p /etc/nagios/adagios
pynag config --append cfg_dir=/etc/nagios/adagios
we should following
[nagios@nagios03 nagios]$ grep ^cfg_dir /etc/nagios/nagios.cfg
cfg_dir=/etc/nagios/servers # <-- existing config dir.
cfg_dir=/etc/nagios/okconfig/ # following 3 lines are added by above pynag command.
cfg_dir=/usr/share/okconfig/templates
cfg_dir=/etc/nagios/adagios
[nagios@nagios03 nagios]$
The status view relies on broker modules livestatus and pnp4nagios, so lets configure nagios.cfg to use those
-bash-4.2$ ls -l /usr/lib64/nagios/brokers/npcdmod.o
-rw-r--r-- 1 root root 19712 Jun 8 2015 /usr/lib64/nagios/brokers/npcdmod.o
-bash-4.2$ ls -l /etc/pnp4nagios/npcd.cfg
-rw-r--r-- 1 root root 4134 Jun 8 2015 /etc/pnp4nagios/npcd.cfg
-bash-4.2$
pynag config --append "broker_module=/usr/lib64/nagios/brokers/npcdmod.o config_file=/etc/pnp4nagios/npcd.cfg"
pynag config --append "broker_module=/usr/lib64/check_mk/livestatus.o /var/spool/nagios/cmd/livestatus"
pynag config --set "process_performance_data=1"
# As nagios user with sudo privilege.
sudo usermod -G apache nagios
sudo systemctl restart nagios && sudo systemctl enable nagios
sudo systemctl restart httpd && sudo systemctl enable httpd
service npcd restart && chkconfig npcd on
- Add the following three lines to the end of the file
# sudo as root from nagios
cat << EOT >> /etc/sudoers.d/adagios
# Nagios daemon control on CentOS 7
%nagios ALL = (root) NOPASSWD: /usr/bin/systemctl
EOT
- See result from above command.
[root@ilclnagios03t ~]# cat /etc/sudoers.d/adagios
Defaults:%nagios !requiretty
%nagios ALL = (root) NOPASSWD: /etc/init.d/nagios
%nagios ALL = (root) NOPASSWD: /sbin/service nagios *
%nagios ALL = (root) NOPASSWD: /usr/sbin/nagios -v /etc/nagios/nagios.cfg
# Nagios daemon control on CentOS 7
%nagios ALL = (root) NOPASSWD: /usr/bin/systemctl
[root@ilclnagios03t ~]#
cat << EOT >> /etc/adagios/adagios.conf
#https://github.com/opinkerfi/adagios/issues/620
ALLOWED_HOSTS = ['*']
EOT
# checking.
[root@nagios03t ~]# tail -2 /etc/adagios/adagios.conf
#https://github.com/opinkerfi/adagios/issues/620
ALLOWED_HOSTS = ['*']
[root@nagios03t ~]#
- unixcat
echo 'GET hosts' | unixcat /var/spool/nagios/cmd/livestatus
- Run the server by direct command line.
# shell command
host="127.0.0.1"
python /usr/lib/python2.7/site-packages/adagios/manage.py runserver ${host}:8000
# log
[root@ilclnagios03t ~]# python /usr/lib/python2.7/site-packages/adagios/manage.py runserver 127.0.0.1:8000
Validating models...
0 errors found
October 04, 2017 - 11:17:59
Django version 1.6.11.6, using settings 'adagios.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
- Run adagios as daemon with systemd service file.
[root@nagios01 system]# cat adagios.service
[Unit]
Description=My Miscellaneous Service
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/usr/lib/python2.7/site-packages/adagios
ExecStart=/usr/bin/python /usr/lib/python2.7/site-packages/adagios/manage.py runserver 192.168.1.31:8000
Restart=on-abort
[Install]
WantedBy=multi-user.target
[root@nagios01 system]#
[root@nagios01 ~]# systemctl enable adagios
Created symlink from /etc/systemd/system/multi-user.target.wants/adagios.service to /usr/lib/systemd/system/adagios.service.
[root@nagios01 ~]# systemctl start adagios
[root@nagios01 ~]# systemctl status -l adagios
● adagios.service - Adagios Service
Loaded: loaded (/usr/lib/systemd/system/adagios.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2018-02-04 09:31:45 EST; 7s ago
Main PID: 24180 (python)
CGroup: /system.slice/adagios.service
├─24180 /usr/bin/python /usr/lib/python2.7/site-packages/adagios/manage.py runserver ilclnagios03:8000
└─24207 /usr/bin/python /usr/lib/python2.7/site-packages/adagios/manage.py runserver ilclnagios03:8000
Feb 04 09:31:45 ilclnagios03 systemd[1]: Started Adagios Service.
Feb 04 09:31:45 ilclnagios03 systemd[1]: Starting Adagios Service...
[root@nagios01 ~]#
[http://localhost:8000]
Go to Misc -> Settings Adjust "nagios url" appropriately, eg http://localhost/nagios
systemctl start httpd
systemctl nagios start
- configure screenshot