Author Archives: Andrew Wells

About Andrew Wells

I have been developing on the LAMP stack since about 2006. I run Ubuntu XFCE on my desktop and have a history of managing Ubuntu and CentOS servers. I code web applications mostly in PHP but have experience with other languages as well. When I'm not working, I can be found working in my home lab or out snowboarding, hiking, camping, or biking depending on the season.

Nagios Plugins 2.2.1 with SSH Remote Exec for Clients

Configure the Server

I assume you already configured the server using this guide: Nagios 4.4.1 Install from Source on Ubuntu 18.04

Log in to your Nagios server and su into the nagios user. You might have to su from root since that account usually doesn’t have a password.

[root@server]$ su - nagios

Out of curiosity, see if you have a .ssh folder.

[nagios@server]$ ls -alh ~/.ssh
ls: cannot access '/home/nagios/.ssh': No such file or directory

More than likely you don’t. So that also means that there is no SSH key pair. Let’s create one.

[nagios@server]$ ssh-keygen

Basically mash the enter key until you see the fingerprint art. We don’t want a passphrase on this key because it will be used by automated scripts.

Now output the public key and save locally for later.

[nagios@server]$ cat .ssh/

Configure the Client(s)

Prepare the Nagios User & Group

[root@client]$ useradd -m -s /bin/bash nagios

Download / Extract Archives

[root@client]$ cd ~
[root@client]$ wget
[root@client]$ tar -xzvf nagios-plugins-2.2.1.tar.gz

By the way, this tar command was written without referencing the docs.

Compile and Install

Install some required packages.

[root@client]$ apt-get install libgd-dev php build-essential unzip libnet-snmp-perl libperl5.26 libpq5 libsensors4 libsnmp-base libsnmp30 libtalloc2 libtdb1 libwbclient0 samba-common samba-common-bin smbclient snmp whois libmysqlclient-dev libssl-dev

Now install them

[root@client]$ cd ~/nagios-plugins-2.2.1
[root@client]$ ./configure --with-nagios-user=nagios --with-nagios-group=nagios
[root@client]$ make
[root@client]$ make install

Add one more

[root@client]$ cd /usr/local/nagios/libexec
[root@client]$ wget
[root@client]$ chmod +x

Authorize Connections

[nagios@client]$ mkdir ~/.ssh
[nagios@client]$ vim ~/.ssh/authorized_keys

Paste in the SSH public key created earlier on the server.

Fix some file permissions.

[nagios@client]$ chmod 0600 ~/.ssh/authorized_keys

Test Commands

Run this lengthy command on the server:

[nagios@server]$ /usr/local/nagios/libexec/check_by_ssh -H -C "/usr/local/nagios/libexec/check_load -w 2,1,1 -c 8,4,4"
OK - load average: 0.14, 0.10, 0.09|load1=0.140;2.000;8.000;0; load5=0.100;1.000;4.000;0; load15=0.090;1.000;4.000;0;

Note that the load average returned is from the client, not the server.

Example Configuration

Below is an example config to start with. You can have a generic command that will call most any remote command. In the service definition, pass the remote command in the first parameter and the warning/critical thresholds in the following parameters. The fourth parameter, $ARG4$ can be used to pass any additional parameters if needed.

define command {
        command_name    check_by_ssh
        command_line    /usr/local/nagios/libexec/check_by_ssh -t 30 -H '$HOSTADDRESS$' -C "/usr/local/nagios/libexec/$ARG1$ -w '$ARG2$' -c '$ARG3$' $ARG4$"

define hostgroup {
    hostgroup_name     hg-linux
    alias              Linux Servers

define service {
    use                     generic-service
    hostgroup_name      hg-linux
    service_description CPU Load
    check_command       check_by_ssh!check_load!4,2,2!8,4,4
    check_interval      1
    retry_interval      1

define host {
    use                     host-generic
    host_name               server-01
    alias                   server-01
    hostgroups              hg-linux

Sanitize Docker Environment

I have a few docker hosts used for development, and sometimes I need to clean out all images/containers/network groups and start from scratch. These commands do just that. Obviously don’t run these on any machines w/ persistent data. Use with caution!

Linux Hosts (no Docker GUI)

Relatively safe cleanup – these commands remove dangling images/volumes that are likely no longer used and just taking up space.

#[root]$ docker system prune -f
#[root]$ docker rmi $(docker images -f "dangling=true" -q)
#[root]$ docker volume rm $(docker volume ls -q -f dangling=true)

More destructive,

#[root]$ docker kill $(docker ps -a -q)
#[root]$ docker rm $(docker ps -a -q)
#[root]$ docker rmi $(docker images -q) -f

MacOS Hosts (Docker GUI)

I’ve had times where the Docker image completely fills up, and cleaning up images to not free up space. So it’s just easier to delete the Virtualbox image and restart Docker.

Delete the Docker VM disk file:

[user]$ rm -f ~/Library/Containers/com.docker.docker/Data/com.docker.driver.amd64-linux/Docker.qcow2

Restart Docker using the Docker GUI.

Gitlab EE/CE with Runners and Docker Registry on Ubuntu 16.04

Where do you store your code projects – Github? What about private projects…do you pay for private repos? You can have more control over your projects and even configure automated tests and builds – all using open source software! Fire up your spare hypervisor and read on to learn how to build your own dev project host!

Continue reading

Nagios 4.x Install from Source on Ubuntu 14.04

I am just starting to upgrade / install Ubuntu 14.04 on my servers, so it’s time to create a guide to install Nagios 4 on Ubuntu 14.04. Apparently Nagios Core install scripts wern’t well tested for Debian systems. But in any case, it can be installed with a couple modifications.

This guide is going to be very similar to my other Nagios install guides.

Continue reading

Offline Migration of KVM Guests

It’s time to enter into summer mode with my lab. By that I mean that it’s time to move important KVM guests off of the HP G5 server and shut that space heater down. Here are my notes with moving guests. If you are looking to move guests from a CentOS to Ubuntu hypervisor, I encourage you to read over my findings. You could also reverse-engineer the article if you are going from Ubuntu to CentOS as well.

Continue reading


Format Correctly in Windows Putty Session

[root]$ NCURSES_NO_UTF8_ACS=1 iftop -i eth0

Config File Examples

Edit the config file on Ubuntu (and probably Debian) boxes:

[user]$ vim ~/.config/htop/htoprc

Edit the file on CentOS (and probably RHEL) boxes:

[user]$ vim ~/.htoprc

Config for 8-Core Boxes

# Beware! This file is rewritten by htop when settings are changed in the interface.
# The parser is also very primitive, and not human-friendly.
fields=0 48 17 18 38 39 40 2 46 47 49 1
left_meters=CPU AllCPUs2 Memory Swap
left_meter_modes=1 1 1 1
right_meters=Hostname Tasks LoadAverage Uptime Clock Battery
right_meter_modes=2 2 2 2 2 2