To configure passive checks in Nagios/icinga I use a tcp listener daemon that launches a script (See Nagios – Using passive checks without agent)
Tried to use inetd superserver daemon, but in the last versions, i have not been able to make it work correctly (See last update in my post: Linux – cannot found / missing inetd.conf)
Anyway I have been able to workaround the problem by using another simple method: tcpserver tool.
This tool, tcpserver, waits for connections from TCP clients. For each connection, it runs a program that is set as parameter.
We will use the same example as I explained in this post (Linux – Create custom inetd service)
Script
The tcpserver will execute this simple script in this example. The script receives text through stding, executes the received command and prints the ouput.
This could be our script (remote-command.sh for example):
#!/bin/bash
read MESSAGE
echo "Command [$MESSAGE]"
echo "-----------------"
$MESSAGE
echo
Give executions perms:
# chmod +x /root/SCRIPTS/remote-command.sh
Install tcpserver tool
In debian, tcpserver tool is included in the ucspi-tcp package
# apt-get install ucspi-tcp
Launch tcpserver manually
This is the basic syntax. Use manpages for more information.
# tcpserver -q -H -R 0.0.0.0 <PORT> <COMMAND/PROGRAM/SCRIPT>
-H Do not look up the remote host name in DNS
-R Do not attempt to obtain $TCPREMOTEINFO from the remote host
# tcpserver -H -R 0.0.0.0 3334 /root/SCRIPTS/remote-command.sh
Test it
Lets execute a command through the tcp service…
# echo "/bin/ls /" | nc 10.10.100.100 3334
Command [/bin/ls /]
-----------------
bin
boot
dev
etc
...
It works!