Hi all,
I am trying to read the information (show info, show stat) from the socket of haproxy with a perl script in order to get a similar result when using the socat command. The problem is that I am not able to read something. I see also a similar example in the sources in the contrib folder, but somehow I don't get the point how to read and print this information.
This is my perl program.
Thanks for any help
###############################################
use strict;
use IO::Socket;
use lib "/usr/local/nagios/libexec";
my $sock = new IO::Socket::UNIX (
LocalAddr => "/var/run/haproxy.socket", Type => SOCK_STREAM, Timeout => 1)
next if !$sock;
print $sock "show info\n";
# here i would like to read out the information from the socket
while(<$sock>){
chomp; print;
# my @d = split('\t');
# print "info data: @d\n";
}check_disk_smb check_mrtgtraf check_spop check_dns check_nagios check_ssh check_dummy check_nntp check_ssmtp check_file_age check_nntps check_swap check_flexlm check_nrpe check_tcp check_ftp check_nt check_time check_hello check_ntp check_udp check_hello.pl check_ntp_peer check_ups check_hpjd check_ntp_time check_users check_http check_nwstat check_wave check_icmp check_oracle root#lobalix01:/usr/local/nagios/libexec# vi check_h check_hello check_hello.pl check_hpjd check_http root#lobalix01:/usr/local/nagios/libexec# vi check_h check_hello check_hello.pl check_hpjd check_http root#lobalix01:/usr/local/nagios/libexec# vi check_h check_hello check_hello.pl check_hpjd check_http root#lobalix01:/usr/local/nagios/libexec# vi check_hello check_hello check_hello.pl
check_apache check_ifstatus check_real check_apache.pl check_imap check_rpc check_apt check_ircd check_sensors check_breeze check_jabber check_simap check_by_ssh check_load check_smtp check_clamd check_log check_snmp check_cluster check_mailq check_spop check_dhcp check_mrtg check_ssh check_dig check_mrtgtraf check_ssmtp check_disk check_nagios check_swap check_disk_smb check_nntp check_tcp check_dns check_nntps check_time check_dummy check_nrpe check_udp check_file_age check_nt check_ups check_flexlm check_ntp check_users check_ftp check_ntp_peer check_wave check_hello check_ntp_time negate check_hello.pl check_nwstat tests/ check_hpjd check_oracle testSocket.pl check_http check_overcr urlize check_icmp check_ping utils.pm check_ide_smart check_pop utils.sh check_ifoperstatus check_procs
root#lobalix01:/usr/local/nagios/libexec# vi check_hello.pl root#lobalix01:/usr/local/nagios/libexec# perl check_hello.pl root#lobalix01:/usr/local/nagios/libexec# vi check_hello.pl root#lobalix01:/usr/local/nagios/libexec# perl check_hello.pl root#lobalix01:/usr/local/nagios/libexec# history | grep socat249 history | grep socat
255 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 256 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 259 echo "show stat" | socat unix-connect:/var/run/haproxy.socketstdioech
262 echo "show statt" | socat unix-connect:/var/run/haproxy.socket stdio 263 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 270 echo "show stat" | socat unix-connect:/var/run/haproxy.socket 271 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdiols272 socat -d -d READLINE,history=$HOME/.http_history \ TCP4:www.domain.org:www,crnl
418 echo "show info" | socat unix-connect:/var/run/haproxy.socket stdio 419 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 420 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 421 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 422 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 423 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 424 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 429 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 430 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 431 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 432 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio510 history | grep socat
pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq,econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg,downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type, iastesting,FRONTEND,,,0,22,2000,206036,17103180,665343376,0,0,0,,,,,OPEN,,,,,,,,,1,1,0,,,,0, iastesting,VIAS10ix1,0,0,0,16,,103018,8551598,332681371,,0,,0,0,0,0,UP,1,1,0,0,0,82051,0,,1,1,1,,103018,,2, iastesting,VIAS10ix2,0,0,0,16,,103018,8551582,332662005,,0,,0,0,0,0,UP,1,1,0,0,0,82051,0,,1,1,2,,103018,,2, iastesting,BACKEND,0,0,0,19,2000,206036,17103180,665343376,0,0,,0,0,0,0,UP,2,2,0,,0,82051,0,,1,1,0,,206036,,1,root#lobalix01:/usr/local/nagios/libexec# echo "show info" | socat unix-connect:/var/run/haproxy.socket stdio Name: HAProxy
check_hello.pl root#lobalix01:/usr/local/nagios/libexec# history | grep socat 249 history | grep socat252 history | grep socat
255 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 256 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 259 echo "show stat" | socat unix-connect:/var/run/haproxy.socketstdioech
262 echo "show statt" | socat unix-connect:/var/run/haproxy.socket stdio 263 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 270 echo "show stat" | socat unix-connect:/var/run/haproxy.socket 271 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdiols272 socat -d -d READLINE,history=$HOME/.http_history \ TCP4:www.domain.org:www,crnl
418 echo "show info" | socat unix-connect:/var/run/haproxy.socket stdio 419 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 420 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 421 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 422 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 423 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 424 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 429 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 430 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 431 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio 432 echo "show stat" | socat unix-connect:/var/run/haproxy.socket stdio510 history | grep socat
check_hello.pl root#lobalix01:/usr/local/nagios/libexec#vi check_hello.pl
root#lobalix01:/usr/local/nagios/libexec# perl check_hello.pl root#lobalix01:/usr/local/nagios/libexec# vi check_hello.pl root#lobalix01:/usr/local/nagios/libexec# perl check_hello.pl root#lobalix01:/usr/local/nagios/libexec# vi check_hello.pluse strict;
my $sock = new IO::Socket::UNIX (
LocalAddr => "/var/run/haproxy.socket", Type => SOCK_STREAM, Timeout => 2)
next if !$sock;
# reading the information of show info and printing in stdout
print $sock "show info\n";
while(<$sock>){
chomp; print;
# my @d = split('\t');
# print "daten: @d\n";
###############################################
Received on 2009/02/14 22:53
This archive was generated by hypermail 2.2.0 : 2009/02/15 00:00 CET