On 9 August 2012 23:17, <oyvind.bjorge at telenor.com> wrote:
Is there anyone that have made a perl module or subroutine for sending to a xymon-server without having to install the xymon client?
You could use xymon-rclient (on xymonton.org), where you only need an ssh connection from the server to a shell running on the client; it automagically sends the client-side script, and injects the results on the server side.
Also, this shell one-liner works on Solaris under ksh, bash and bourne shell (sh):
#!/bin/sh ( echo "$2"; sleep 1 ) | telnet $1 1984 2>&1 >/dev/null | grep -v "closed by foreign host"
Run it like this:
./xymon.sh $XYMSRV "status uname -n.testname green All OK"
Alternatively, netcat (nc) can be used like so:
echo "$2" | nc -w1 $1 1984 || echo "Connection failure"
Neither of these are ideal, because there's no way to close the connection on the client side once the message has been sent, and so it simply waits 1 second (-w1 for nc) and assumes it has all been sent.
This bash code doesn't have the same limitation. It works on Linux and should work on all UNIXes that run bash:
#!/bin/bash
exec 3<>/dev/tcp/$1/1984 || exit 1
echo "status uname -n.testing green date $2" >&3
Run it as above.
This script uses the /dev/tcp bash-ism, so it's not portable to other shells. If you needed to send multiple messages in a single script, you should close the socket after each with "exec 3<>-".
J