Dry contact solution

Rob Enders renders at cknxradio.com
Sun Feb 8 18:51:04 CET 2004


Hi all.. Recently there has been some questions about monitoring dry
contacts.. Here is a solution that I have used successfully for 4 years, I
have two joysticks ports ( 8 contacts) . I am still using Netsaint, for no
other reason that a lack of time to rebuild the machine to use Nagios but
the plugin should work the same..

Good luck

Rob

From:           	"Rob Enders" <...>
To:             	<netsaintplug-devel at lists.sourceforge.net>
Date sent:      	Mon, 6 Nov 2000 21:47:49 -0500
Subject:        	[Netsaintplug-devel] JoyStick Button Plugin

I have managed to kludge together a joystick button monitoring plugin
using joyd http://www.h.shuttle.de/mitch/joyd.en.html. I am using it for
monitoring audio silence sensors at our radio station.  It could also be
used for smoke/fire detectors, motion sensors, etc. It works as follows:

I have wired up a connector to a standard audio card joystick port,
simulating a 2 axis 4 button analog joystick.
The button inputs wired to relays that are part of an audio silense
monitor. The linux joystick modules, joystick.o and joy-analog.o are
needed. The current version of joyd, 0.2.2 requires a complete press and
release of the button to complete an action. I modified the code in line
246 of joystick.c of the joyd package from:

	if ((button_normal == 0) && (axis_normal == 0)

to:

	if (button_normal!= 0) && (axis_normal == 0)

This changed the detection routine to button presses only. Joyd is a
joystick
monitoring daemon that turns button presses into commands. I assigned the
following command to each button:

/usr/local/netsaint/libexec/eventhandler/submit_check_result <hostname>
<service long name> 2  <description>

The event handler is identical to the sample in the documentation for
portsentry. I created a plugin called check_joystick using one of the
other scripts (check_sensor)in the latest tarball as follows:


#! /bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin

PROGNAME=`basename $0`
PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`
REVISION=`echo '$Revision: 1.0 $' | sed -e 's/[^0-9.]//g'`
STATUS=""

. $PROGPATH/utils.sh


print_usage() {
        echo "Usage: $PROGNAME /dev/js<#> <button #>"
}

print_help() {
        print_revision $PROGNAME $REVISION
        echo ""
        print_usage
        echo ""
        echo "This plugin checks a joystick button status using the " echo
        "joyreadbutton utility from the joyd package." echo "" support
        exit 0
}

if [ $# -ne 2 ]; then
        print_usage
        exit 0
fi

case "$1" in
        --help)
                print_help
                exit 0
                ;;
        -h)
                print_help
                exit 0
                ;;
        --version)
        print_revision $PROGNAME $REVISION
                exit 0
                ;;
        -V)
                print_revision $PROGNAME $REVISION
                exit 0
                ;;
        /dev/js*)
                joyreadbutton $1 $2 1>&1 1>/dev/null
                STATUS=$?
                if [ "$STATUS" -eq 0 ]; then
                        echo OK
                        exit 0
                elif [ "$STATUS" -eq 1 ];then
                        echo CRITICAL
                        exit 2
                else
                        echo UNKNOWN
                        exit -1
                fi
                ;;
        *)
                print_usage
                exit 0
                ;;
esac


This plugin is called by the same service that the submit_check_results
event handler calls.. The plugin calls a utility program included with
joyd that returns a exit code based on the status of the button. The
plugin changes it to the appropriate value for CRITICAL or OK. I can't
quite get the script to exit UNKNOWN when the joyreadbutton program fails
so any thoughts here are appreciated. Here is the service:

service[<hostname>]=AM Silence
Monitor;1;24x7;1;300;30;admins;600;24x7;1;1;0;;check_joystick!/dev/js0!0

BTW, I have suggested to Christian via email, the originator of joyd, that
for the purposes of Netsaint, he provide an option to output a command for
each press and release of the button. This would remove the need to test
the button status from netsaint since in my case with the relay open,
everything is OK, relay closed, OFF THE AIR!.

As you might notice, I am not a programmer, or for the matter even a
hacker. I have combined a number of interesting parts to provide me with
the features I need. If anyone has any suggestions, or wants to fix this
up, please do so and share the code. I can use all the help I can get.. I
hope that others will find this useful.

Ciao

Rob



-------------------------------------------------------
The SF.Net email is sponsored by EclipseCon 2004
Premiere Conference on Open Tools Development and Integration
See the breadth of Eclipse activity. February 3-5 in Anaheim, CA.
http://www.eclipsecon.org/osdn
_______________________________________________
Nagios-users mailing list
Nagios-users at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/nagios-users
::: Please include Nagios version, plugin version (-v) and OS when reporting any issue. 
::: Messages without supporting info will risk being sent to /dev/null





More information about the Users mailing list