Wednesday, April 8, 2009

Zenoss monitor remote customized application via SSH


I have used 3 open source NMS apps, nagios,openNMS, Zenoss. Zenos is the best i have found so far. Nagios doesn’t support SNMP and no graphing ability. OpenNMS supports SNMP and graphing but it needs restart for new config to be effective.
Zenoss doesn’t have native NRPE plugin like OpenNMS, But Zenoss has the ability to run customized application though the ZenCommand process, ZenCommand can run any command locally and remotely by using a native SSH transport. When run, Zenoss tracks the return code( 0 =success, !0= fail)
Zenoss can monitor customized applications by various methods e.g SSH/NRPE/SNMP, this note demonstrates SSH method


#==On the remote host, create a test script
$vi /usr/local/bin/check_test.sh


flag=1
if [ $flag -eq 0 ]; then
echo "check test-OK"
exit 0
else
echo "check test-FAILED"
exit 1
fi

$chmod +rx /usr/local/bin/check_test.sh

#==On zenoss
#====Test ssh remote command manually with password authentication
ssh zenoss@remote-ip /usr/local/bin/check_test.sh


#====set ssh username/password on Zenoss

Classess--Devices--zProperties
zCommandPassword
zCommandUsername =zenoss
if you prefer to use ssh key, only enter zCommandUsername ( it appears only dsa type key works)
It is global setting for all devices, it apply to any devices.


#====Create template to use the script

Classes--Devices--Templates--Add Template (add template is hidden drop down menu brought up by clicking the small triangle button)
New data Source ( ID: userdefined TYPE: command)




Enabled:true
use ssh :true
Event Class:/cmd/fail
Severity:error
Command Template:/usr/local/bin/check_test.sh
#====Bind the template to your Device
Device List--yourdevice--Open--
Click the small triangle button--More--Template
Click the small triangle button--Bind Templates--add new template to selection (You can select multiple templates)
#====Test
/opt/zenoss/zenoss/bin/zencommand run -d 10.248.248.22 -v10



INFO:zen.zencommand:---------- - schedule has 1 commands
DEBUG:zen.zencommand:Next command in 299.977344 seconds
DEBUG:zen.SshClient:10.248.248.22 host key: 66:d3:e2:09:45:80:36:0d:16:77:0a:db:7a:9d:4a:e6
DEBUG:zen.SshClient:creating new SSH connection...
DEBUG:zen.SshClient:Attempting to authenticate using username: zenoss
DEBUG:zen.SshClient:Getting SSH public key from ~/.ssh/id_dsa
DEBUG:zen.SshClient:Expanded key path from ~/.ssh/id_dsa to /home/zenoss/.ssh/id_dsa
DEBUG:zen.SshClient:Getting SSH private key from ~/.ssh/id_dsa
DEBUG:zen.SshClient:Expanded key path from ~/.ssh/id_dsa to /home/zenoss/.ssh/id_dsa
INFO:zen.SshClient:Connected to device 10.248.248.22
DEBUG:zen.SshClient:started the channel
DEBUG:zen.SshClient:opening command channel for /usr/local/bin/check_test.sh
DEBUG:zen.SshClient:running command remotely: exec /usr/local/bin/check_test.sh
DEBUG:zen.SshClient:command /usr/local/bin/check_test.sh data: 'check test-FAILED\n'
DEBUG:zen.zencommand:Process check_test.sh stopped (1), 1.614611 elapsed
DEBUG:zen.zencommand:The result of "/usr/local/bin/check_test.sh" was "check test-FAILED


As output shows, it connected to remote host via ssh then run the command /usr/local/bin/check_test.sh
Back to GUI, the alarm should appear in event log of the device.

3 comments:

  1. [root@zenoss ~]# /opt/zenoss/bin/zencommand run -d 172.19.73.5 -v10
    /opt/zenoss/bin/zencommand: line 12: /bin/zenfunctions: No such file or directory
    /opt/zenoss/bin/zencommand: line 18: generic: command not found

    ReplyDelete
  2. Remote Monitoring
    https://evtintegration.uk/
    We are a Remote Monitoring & System Integration Companies and control 4 authorised dealers. We integrate all aspects of technology through the control 4 amarthome app.

    ReplyDelete