Skip to content

Instantly share code, notes, and snippets.

@kenjiskywalker
Created May 1, 2012 11:06
Show Gist options
  • Save kenjiskywalker/2567358 to your computer and use it in GitHub Desktop.
Save kenjiskywalker/2567358 to your computer and use it in GitHub Desktop.
make zabbix screen script
#!/usr/bin/env perl
use strict;
use warnings;
use Text::Xslate;
use Time::Piece ();
my $time = Time::Piece::localtime();
my $day;
my $hour;
$day = $time->strftime('%y.%m.%d');
$hour = $time->strftime('%H.%m');
my $tx = Text::Xslate->new();
$tx->load_file('./zabbix_screen.tx');
my $in_file = './zabbix_screen.csv';
my $host_data;
my @datas;
my $srnm;
my $out_file;
my $x = 0;
my $y = 0;
my $z = 0;
my $hsize = 0;
my $vsize = 0;
open my $ifh, '<', $in_file
or die "Can't open file \"$in_file\": $!";
while ( my $line = <$ifh>){
my ( $file, $host, $name, $screenname, ) = split(/,/, $line);
$out_file = "$file.xml";
$srnm = $screenname;
$host_data = {
host => $host,
name => $name,
x => $x,
y => $y,
};
push(@datas, $host_data);
if ( $x == 1 ) {
$x = 0;
} else {
$x = 1;
};
if ( $z == 0 ) {
$z++;
} else {
$z = 0;
$y++;
};
}
$hsize = 2;
$vsize = $y;
my $content = $tx->render("test.tx", {
day => $day,
hour => $hour,
srnm => $srnm,
hsize => $hsize,
vsize => $vsize,
data => \@datas,
}
);
open my $ofh, '>', $out_file;
print $content;
print $ofh $content;
close($ofh);
__END__
cpu_zabbix_xml web01 Network Traffic(eth0) Hoge Service Network Traffic
cpu_zabbix_xml web02 Network Traffic(eth0) Hoge Service Network Traffic
cpu_zabbix_xml app01 Network Traffic(eth0) Hoge Service Network Traffic
cpu_zabbix_xml app02 Network Traffic(eth0) Hoge Service Network Traffic
cpu_zabbix_xml app03 Network Traffic(eth0) Hoge Service Network Traffic
cpu_zabbix_xml db01 Network Traffic(eth0) Hoge Service Network Traffic
cpu_zabbix_xml db02 Network Traffic(eth0) Hoge Service Network Traffic
cpu_zabbix_xml cache01 Network Traffic(eth0) Hoge Service Network Traffic
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export version="1.0" date="<: $day :>" time="<: $hour :>">
<screens>
<screen>
<screenitems>
: for $date -> $hoge {
<screenitem>
<resourcetype>0</resourcetype>
<resourceid>
<host><: $hoge.host :></host>
<name><: $hoge.name :></name>
</resourceid>
<width>500</width>
<height>100</height>
<x>$hoge.x</x>
<y>$hoge.y</y>
<colspan>0</colspan>
<rowspan>0</rowspan>
<elements>0</elements>
<valign>0</valign>
<halign>0</halign>
<style>0</style>
<dynamic>0</dynamic>
</screenitem>
: }
</screenitems>
<name><: $srnm :></name>
<hsize><: $hsize:></hsize>
<vsize><: $vsize:></vsize>
</screen>
</screens>
</zabbix_export>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment