Nagios Event Handlers

Restarting-Linux-Services-With-NRPE
https://assets.nagios.com/downloads/nagiosxi/docs/Restarting-Linux-Services-With-NRPE.pdf

At each monitored server
————————
Add this line to /usr/local/nagios/etc/nrpe.cfg :
command[service_restart]=sudo service $ARG1$ restart 2>&1

And give nagios permissions to execute service
echo “nagios ALL = NOPASSWD: `which service`” > /etc/sudoers.d/nagios

At the Nagios XI server
———————–
– Test with
/usr/local/nagios/libexec/check_nrpe -H 10.25.13.34 -c service_restart -a apache2
– add these contents to /usr/local/nagios/libexec/service_restart.bash
#!/bin/bash
case “$1” in
OK)
;;
WARNING)
;;
UNKNOWN)
;;
CRITICAL)
/usr/local/nagios/libexec/check_nrpe -H “$2” -c service_restart -a “$3”
;;
esac
exit 0

– set permissions
chown apache:nagios /usr/local/nagios/libexec/service_restart.bash
chmod 775 /usr/local/nagios/libexec/service_restart.bash

-test
/usr/local/nagios/libexec/service_restart.sh CRITICAL 10.25.13.34 apache2

– Create a “command” in the core config mannager with this command line:
$USER1$/service_restart.sh $SERVICESTATE$ $HOSTADDRESS$ $_SERVICESERVICE$
Also select “misc_command” from command type

– Update a service adding the event handler

– in the misc settings add a “free variable”
_SERVICE apache2

Read:
https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/eventhandlers.html#example
http://www.techadre.com/content/nagios-event-handler-restart-remote-service

Nagios event handlers for NRPE


https://assets.nagios.com/downloads/nagioscore/docs/nagioscore/3/en/objecttricks.html

install nagios xi agent

for ElementaryOS

# apt install xinetd libssl-dev build-essential
# cd /tmp; wget https://assets.nagios.com/downloads/nagiosxi/agents/linux-nrpe-agent.tar.gz
# tar zxvf linux-nrpe-agent.tar.gz
# cd linux-nrpe-agent
# vi fullinstall
(after the 4th line insert a line distro=Ubuntu)
# ./fullinstall

Docker cheat sheet

# docker version
# docker info
# docker run hello-world
# docker ps
# docker ps -a
# docker images
(image=non-running vm)
(container=running image)
# docker pull alpine
# docker pull ubuntu
# docker pull ubuntu:14.04

To remove an image
# docker rmi ubuntu:14.04

To stop a container
# docker stop ubuntu

Start ubuntu container, name it temp, connect to it
# docker run -it –name temp ubuntu:latest /bin/bash
(to exit the console type ctrl-p-q)

Stop all containers
# docker stop $(docker ps -aq)

Remove all containers
# docker rm $(docker ps -aq)

Remove all images
# docker rmi $(docker images -q)

Install docker on centos7 and ElementaryOS loki and hera

From https://docs.docker.com/engine/install/

For Centos7

# yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
# yum install -y yum-utils
# yum-config-manager –add-repo https://download.docker.com/linux/centos/docker-ce.repo
# yum -y install docker-ce docker-ce-cli containerd.io
# systemctl start docker
# systemctl enable docker

For ElementaryOS Hera

# apt-get remove docker docker-engine docker.io containerd runc
# apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
# add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable”
# apt update
# apt-get install docker-ce docker-ce-cli containerd.io

For ElementaryOS loki

# apt-get remove docker docker-engine docker.io containerd runc
# apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
# curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add –
# add-apt-repository “deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable”
# apt update
# apt-get install docker-ce docker-ce-cli containerd.io

show printjobs per printer

This script shows all printjobs classified by printer.
this is useful to see which jobs are stalled in misconfigured printers.

#!/bin/bash

lpstat -o > jobs.txt
echo “Total Jobs: $(wc -l jobs.txt)”
lpstat -a | awk ‘{ print $1 }’ | while read p;do
J=$(grep $p jobs.txt|wc -l)
if [ $J -gt 0 ];then
nj=$(grep $p jobs.txt | wc -l)
echo ” $p : ${nj} jobs ———————-”
lpstat -p $p | egrep -iv ‘reason’
fi
done

Mirror all redhat 7 repositories

First ,make sure you have a system that is registered, then run this script

#!/bin/bash
(
grep ‘\[‘ /etc/yum.repos.d/redhat.repo | sed ‘s/\[//g;s/\]//g’ | while read repo;do
reposync –gpgcheck -l –repoid=$repo –download_path=/swdepot/repos/ –downloadcomps –download-metadata
done
for d in $(ls /swdepot/repos);do
cd /swdepot/repos/$d
createrepo -v /swdepot/repos/$d
done
) >>/var/log/reposync.log 2>&1