Forum Discussion
John_Gruber_432
Jan 03, 2008Historic F5 Account
Remote Command Execution with Simple Socket Server
I had a customer with the need to run a remote command and parse its output as a monitor. The remote command was a compiled binary with libs only available on their server. There are many ways to do this, but we wanted something easily changed and light weight on the LTM.
What we did was run a TCP monitor which input command line arguments to the remote machine and then wrote a simple perl socket server to receive the monitor connection and pull the arguments from the monitor Send String value and then send the commands output back to the monitor to parse in its Receive String.
I've attached the perl server and coded into it the ping command. It uses only lib Socket so it should work even on old perl installs. No threading support needed, it uses fork. There is nothing fancy in it and it is easily customized.
The monitor below will mark host up if www.yahoo.com returns pings by using the supplied perl socket server on a remote machine. In this case 192.168.0.2..
monitor remote_cmd {
defaults from tcp
interval 10
timeout 31
dest 192.168.0.2:9090
recv "3 packets transmitted, 3 received"
send "www.yahoo.com"
}
This could be expanded to pull back status from any command line on a remote machine and parse its output. Change the command to 'ls -l $arg' and check for a certain file date on a remote machine. Change it to 'ps -ef|grep $arg' and make sure a remote service is still running. Change it to 'mysql < tablevaluecheck.sql' and get pull from a database. The possibilities are endless! Let me know cool things you do with it! And... build in some security!
Thanks David for letting me share our solution to your problem!
As always... test test test... Your mileage may very.
Happy Monitoring
John Gruber
F5 Field Systems Engineer
No RepliesBe the first to reply
Recent Discussions
Related Content
DevCentral Quicklinks
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com
Discover DevCentral Connects