See www.zabbix.com for the official Zabbix site.

Docs/protocols/zabbix sender/1.1/perl example

From Zabbix.org
Jump to: navigation, search

Zabbix sender protocol implementation in Perl

use IO::Socket;
use IO::Select;
use MIME::Base64;

sub zabbix_sender
{
 my ($zabbixserver,$hostname,$item,$data) = @_;
 my $timeout=10;

 my $request=sprintf("<req>\n<host>%s</host>\n<key>%s</key>\n<data>%s</data>\n</req>\n",
 encode_base64($hostname),encode_base64($item),encode_base64($data));

 my $sock = new IO::Socket::INET ( PeerAddr => $zabbixserver, PeerPort => '10051', Proto => 'tcp', Timeout => $timeout);
 die "Could not create socket: $!\n" unless $sock;
 $sock->send($request);
 my @handles=IO::Select->new($sock)->can_read($timeout);
 if (scalar(@handles) > 0)
 {
  $sock->recv($result,1024);
  print "answer from zabbix server $zabbixserver: $result\n";
 }
 else
 {
  print "no answer from zabbix server\n";
 }
 $sock->close();
}