Skip to content

Instantly share code, notes, and snippets.

@astail
Created June 17, 2015 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astail/97f0b01cf65b48d4b8ab to your computer and use it in GitHub Desktop.
Save astail/97f0b01cf65b48d4b8ab to your computer and use it in GitHub Desktop.
#!/bin/sh
# zabbixのスクリーンにインポートするxmlをつくるシェルスクリプト。
# 完全に自分用 いらなそうな処理もあるけど。
# zabbix2.2
# 100台以上の想定はしてない(そもそもその数をスクリーンで見ると重い)
# $ sh zbx_screen.sh > out.xml でxmlをインポートする。
host_name="astel00"
server_number=42
Screen_name="astel CPU load"
Graph_name="CPU load"
hsize=2
vsize=`expr $server_number / $hsize`
date=`date +%Y-%m-%dT%H:%M:%SZ`
cat << EOF
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>2.0</version>
<date>$date</date>
<screens>
<screen>
<name>$Screen_name</name>
<hsize>$hsize</hsize>
<vsize>$vsize</vsize>
<screen_items>
EOF
i=1
x=0
y=0
if [ $server_number -lt 10 ]; then
host="0$server_number"
else
host="$server_number"
fi
while [ $i -le $server_number ]
do
if [ $i -lt 10 ]; then
i="0$i"
else
i="$i"
fi
cat << EOF
<screen_item>
<resourcetype>0</resourcetype>
<width>500</width>
<height>100</height>
<x>$x</x>
<y>$y</y>
<colspan>1</colspan>
<rowspan>1</rowspan>
<elements>0</elements>
<valign>0</valign>
<halign>0</halign>
<style>0</style>
<url/>
<dynamic>0</dynamic>
<sort_triggers>0</sort_triggers>
<resource>
<name>$Graph_name</name>
<host>$host_name$i</host>
</resource>
<application/>
</screen_item>
EOF
if [ $i -lt 10 ]; then
i=`echo $i | cut -b2`
fi
xy=`expr $i % 2`
if [ $xy -ne 0 ]; then
x=1
else
x=0
y=`expr $y + 1`
fi
i=`expr $i + 1`
done
cat <<EOF
</screen_items>
</screen>
</screens>
</zabbix_export>
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment