Check by SSH



SSH is an easy and secure way, to execute monitoring plugins on a remote host.

Create SSH-Key on your openITCOCKPIT Server

If you don't have a SSH-Key for your user nagios yet, you need to create one.

su nagios
mkdir /var/lib/nagios/.ssh
ssh-keygen

Also you should import the ssh host key of the target host right now: ssh <target-host> and just confirm with yes.

Import SSH-Key on target host

For this example you need to install the nagios-plugins or monitoring-plugins on the target host.

apt-get install nagios-plugins

In the next step create a new user monitoring which will be used to execute the checks via SSH.

addgroup --system monitoring
adduser --system --shell /bin/bash monitoring
adduser monitoring monitoring

mkdir -p /home/monitoring/.ssh/
chown monitoring:monitoring /home/monitoring -R

touch /home/monitoring/.ssh/authorized_keys
chmod 644 /home/monitoring/.ssh/authorized_keys

Now copy your public key to the file /home/monitoring/.ssh/authorized_keys

Create checks

Navigate to Objects Commands and make sure that the check_by_ssh command exists. It's a default command of openITCOCKPIT. If the command is missing on your system press on + New to create it.

Command defenition
Command type Service check command
Command name check_by_ssh
Command line $USER1$/check_by_ssh -H $HOSTADDRESS$ -l "$ARG1$" -C "$ARG2$".
Command arguemnt ($ARG1) Username
Command arguemnt ($ARG2) Command

The check_by_ssh plugin can be used to execute all types of commands on the remote maschine. To run check plugins it is required to set the full path to the plugin. To avoid a lot of work and keep things flexible its recommended to use a Macro to store the plugin path.

Go to Objects User Defined Macros and press on + New.

Macro defenition
Macro name $USER2$ (or any other)
Value /usr/lib/nagios/plugins
Description (optional) Path of monitoring-plugins on remote host used by check_by_ssh.

Navigate to Services and press on + New.

Select your host and chosse the predefined service template CHECK_BY_SSH

Service defenition
Service template CHECK_BY_SSH
Service name CPU load
Check command check_by_ssh.
Username ($ARG1) monitoring
Command ($ARG2) $USER2$/check_load -w 15,10,5 -c 30,25,20

To continue press Create service.

$USER2$ will be automatically replaced with the value from the macro defined earlier.

Repeat this step for as many services as you like.

To enable the new configuration, you need to run Refresh monitoring configuration.

Press Launch refresh to apply the new configuration.

The new services will be now monitored by the system: