Tag Archives: Ubuntu

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/id_rsa.pub

Configure the Client(s)

Install Option #1 – Install From Source

[root@client]$ useradd -m -s /bin/bash nagios
[root@client]$ cd ~
[root@client]$ wget http://www.nagios-plugins.org/download/nagios-plugins-2.2.1.tar.gz
[root@client]$ tar -xzvf nagios-plugins-2.2.1.tar.gz

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

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

Option #2 – Apt Install

[root@client]$ useradd -m -s /bin/bash nagios
[root@client]$ apt-get install nagios-plugins

I reference all plugin paths from the source install, so create a link if you do the deb package.

[root@client]$ ln -s /usr/lib/nagios/plugins /usr/local/nagios/libexec

Additional Plugin Install

[root@client]$ cd /usr/local/nagios/libexec
[root@client]$ wget https://raw.githubusercontent.com/justintime/nagios-plugins/master/check_mem/check_mem.pl
[root@client]$ chmod +x check_mem.pl

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

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

Purging old Kernels in Ubuntu

Ubuntu likes to cut space on my /boot partitions awfully close when using their auto-partition method at install time. I had an apt update fail once because of a full /boot partition and have been keeping an eye on them since. They frequently fill past 80%, so I clean out the old kernels when this happens. There is probably more of an automated way to do it, but this works for now.

Continue reading