Zabbix – SSH checks

Zabbix can execute shell commands over SSH and record the results.  This ability does not require a Zabbix agent, which is helpful for remote machines.

I use Zabbix SSH checks to verify logins to an SFTP server.

SSH checks in Zabbix are not enabled by default.  You’ll have to enable them in the zabbix_server.conf file as well as compiling support into the server when you build it.

To compile support into the server make sure you add –with-ssh2 to your configure.  You will probably also have to add libssh2 libraries if you get an error like this during your configure

checking for SSH2 support... no
configure: error: SSH2 library not found

I’m running CentOS 5.8 and the repositories I have set up do not have a recent version of 32 bit libssh2.  The 64 bit version that installs is libssh2-1.2.7.1, but that’s not good enough for Zabbix.

I found a 1.2.7.1 RPM for 32 bit libssh2 at http://pkgs.repoforge.org/libssh2/.  Once installed, the configure completes with the –with-ssh2 flag.

After your Zabbix binaries are built.  Edit the zabbix_server.conf configuration file and modify  the SSHKeyLocation to set the full path of the folder where your public and private keys are located.

I use the home directory of the zabbix user

SSHKeyLocation=/home/zabbix/.ssh

Save the modified configuration file and restart the zabbix_server to activate the changes.

Create public and private keys:

# sudo -u zabbix ssh-keygen -t rsa

I did not enter a passphrase for the key pair, but it’s probably best to use a passphrase.

Two files, id_rsa.pub and id_rsa, will be created in the /home/zabbix/.ssh directory and this directory is specified in the zabbix_server.conf file.

Copy the public key to the server you wish to use this check on.  There are many methods, but I use this one regularly:

ssh <username>@<server> "mkdir .ssh; chmod 0700 .ssh; chown <username> .ssh"
cat .ssh/id_rsa.pub | ssh -l <username> <server> "cat - >>.ssh/authorized_keys"
ssh <username>@<server> "chmod 0600 .ssh/authorized_keys; chown <username> .ssh/authorized_keys"

Test your connection after copying SSH key files

sudo -u zabbix ssh <username>@<server>

Create item for your new check

Host                     c_Template_SSHcheck
Description              SSH check
Type                     SSH agent
Key                      ssh.run[1]
Authentication method    Public key
User name                <username>
Public key file          id_rsa.pub    
Private key file         id_rsa
Password    
Executed script          hostname -s
Type of information      Text
Update interval (in sec) 300    
Flexible intervals (sec) No flexible intervals
New flexible interval    Delay Period
Keep history (in days)   7
Status                   Active
New application          SSH    
Applications

http://www.zabbix.com/documentation/2.0/manual/config/items/itemtypes/ssh_checks

Once your item is created, check Latest Data in Zabbix for your new SSH checks. If you don’t see any results be sure to look into the Zabbix logs for more details.

Zabbix SSH checks add simple agentless monitoring to your environment, extending the functionality of Zabbix.

Advertisements

Zabbix 2.0 low level discovery – file system

Zabbix 2.0 makes it easy to add network devices, file systems, and SNMP devices for monitoring.  They call their new method low-level discovery and I will show you how I set it up so you can quickly start monitoring your environment.

I’ll first show you how to set up low-level discovery for file systems.  Later you’ll see how to set it up for network devices and SNMP.

Low level discovery of file systems is a big improvement over how you managed file systems in previous Zabbix releases.  You no longer have to assign specific drive letters to a host or remove drives that are ‘unsupported’ from that host.

I have created file system discovery rules in the Windows template and the Linux template.

Windows Discovery Rules

The new discovery rules are created in the Zabbix UI under Configuration, Templates, Discovery.   Here are the details for setting up the low level file system discovery for the Windows template.

Name: Windows FS Discovery
Type: Zabbix agent (active)
Key: vfs.fs.discovery
Update interval: 7200
Keep lost resource period: 1
Filter macro: {#FSTYPE}
Regexp: NTFS|FAT32
Windows LDD file system discovery rule

Windows LDD file system discovery rule

Windows Item Prototypes

Once the discovery entry is made, you should create item prototypes for the items you are interested in.  The prototype will be applied to each of the discovered file system item.

I created 4 prototype items for the Windows low level file system discovery.

  • Free disk space (%)
  • Free disk space
  • Total disk space
  • Used disk space

Each item prototype is pretty much the same, just a change for the name and key.

Free disk space (%)

Name: Free disk space (%) - $1
Type:Zabbix agent (active)
Key: vfs.fs.size[{#FSNAME},pfree]
Type: Numeric (float)
Units: %
Update interval: 300
Keep history: 7
Keep trends: 365
Applications: Availability, Filesystem
Windows LDD item prototype

Windows LDD item prototype

Free disk space

Name: Free disk space - $1
Type:Zabbix agent (active)
Key: vfs.fs.size[{#FSNAME},free]
Type: Numeric (float)
Units: B
Update interval: 300
Keep history: 7
Keep trends: 365
Applications: Availability, Filesystem

Total disk space

Name: Total disk space - $1
Type:Zabbix agent (active)
Key: vfs.fs.size[{#FSNAME},total]
Type: Numeric (float)
Units: B
Update interval: 300
Keep history: 7
Keep trends: 365
Applications: Availability, Filesystem

Used disk space

Name: Used disk space - $1
Type:Zabbix agent (active)
Key: vfs.fs.size[{#FSNAME},used]
Type: Numeric (float)
Units: B
Update interval: 86400
Keep history: 7
Keep trends: 365
Applications: Availability, Filesystem

Trigger prototypes are similar to item prototypes.  Here is one example

Name: Low free disk space % - {HOST.NAME} {#FSNAME}
Expression: {c_Template_Windows:vfs.fs.size[{#FSNAME},pfree].last(0)}<10
Severity: High

Linux Discovery Rules

The details for setting up the low level file system discovery for the Linux template is similar to the Windows setup.

Here are the details for setting up the low level file system discovery for the Linux template.

Name: Linux FS Discovery
Type: Zabbix agent (active)
Key: vfs.fs.discovery
Update interval: 7200
Keep lost resource period: 1
Filter macro: {#FSTYPE}
Regexp:(nfs|ext3)

Linux low level FS discovery

The item prototypes for Linux are exactly the same as the Windows item prototypes, so I will not show show specific Linux examples.

That’s about it.  The addition of low-level discovery in Zabbix is fantastic and I’m sure you will immediately see how helpful it can be once you get it set up in Zabbix 2.0.

Let me know what you think about this new feature.  I’ll post information about network discovery and SNMP discovery shortly.