Пятница, 10 июня 2011 г.

Export static graphs from Zabbix same as Cacti

Просмотров: 3397 | Подписаться на комментарии по RSS |

I like see static content without dynamic refresh pages same as export from the cacti static content. But zabbix can't do it. You can see this is script getting static graphs and generate a pages for show graphs.

#!/bin/sh
####################
http="https"
host="myhost"
name=zabbix_username
password=zabbix_password
path_graphs=/usr/local/www/zabbix/static/tmp
zabb_log=/tmp/zabbix_static.log
width=800
####################
PATH='/bin:/usr/bin:/usr/local/bin:/usr/bin/X11:/usr/games:/sbin:/usr/sbin:/usr/local/sbin'
result=$(wget --no-check-certificate --save-cookies=/tmp/cookie.txt --keep-session-cookies --post-data "name=${name}&password=${password}&enter=Enter" -O - -q ${http}://${host}/index.php?login=1 | grep window.location)
if [ ! -d ${path_graphs} ];then
	mkdir ${path_graphs}
fi
get_pic() {
	if [ "$result" ];then
		echo '<td><a href='tmp/${1}.html'><H2>'${1}'</H2></a></td>'>>${path_graphs}/../index.php 
		head_html ${1}
		for x in ${2};do
			echo "`date +"%H:%M:%S"`: graph ${1}_${x} done" >> ${zabb_log}
			for i in 3600 86400;do 
				wget --no-check-certificate --load-cookies=/tmp/cookie.txt -O ${path_graphs}/${1}_${x}_${i}.jpg -q "${http}://${host}/chart2.php?graphid=${x}&width=${width}&period=${i}"
				if [ ${i} -eq 3600 ];then
					echo '<tr valign=center><td align=center>Hour</td></tr>' >>  ${path_graphs}/${1}.html
				elif [ ${i} -eq 86400 ];then
					echo '<tr valign=center><td align=center>Day</td></tr>' >>  ${path_graphs}/${1}.html
				else
					exit 0
				fi
				echo '<tr valign=center><td align=center><a href='${http}://${host}'/charts.php?&form_refresh=1&graphid='${x}'><img src='${1}_${x}_${i}.jpg'></a></td></tr>' >> ${path_graphs}/${1}.html
			done
		done
		echo '</table><a href=../>back</a></body></html>'>>${path_graphs}/${1}.html 
		sed -i .orig 's|%%UPDATE%%|'`date +%H:%M:%S/%Z`'|g' ${path_graphs}/${1}.html && rm ${path_graphs}/${1}.html.orig 
		echo "`date +"%H:%M:%S"`: generate ${1}.html is done" >> ${zabb_log}
	fi
}
head_html() {
	cat > ${path_graphs}/${1}.html <<_END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Language" content="ru">
<meta http-equiv="Content-Type" content="text/html; charset=koi8r">
<title>Graphs ${1}</title></head>
<body>

<h1>Last update: %%UPDATE%%</h1>
<a href=../>back</a>

<table border=0 width=100% height=100%>

<tr>
<td align=center colspan=2>

<h1> ${1} graphs </h1></td></tr>
_END
}
start_get() {
	case $1 in 
		cpu)
			get_pic ${1} '1 2 3'
		;;
		la)
			get_pic ${1} '37 40 39'
		;;
		*)
			echo '</tr></table></body></html>'>>${path_graphs}/../index.php
		;;
	esac
}
if [ ${http} = 'http' ];then
	if ! telnet ${host} 80 < /dev/null 2>&1 | grep -q Connected;then
		exit 0
	fi
elif [ ${http} = 'https' ];then
	if ! openssl s_client -connect ${host}:443 -state </dev/null 2>&1 |grep CONNECTED;then
		exit 0
	fi
else
	exit 0
fi
if [ -f /tmp/cookie.txt ];then
	/tmp/cookie.txt
fi
if [ -f ${zabb_log} ];then
	rm ${zabb_log}
fi
if [ -d ${path_graphs} ];then
	rm ${path_graphs}/*
else
	mkdir ${path_graphs}
fi
cat > ${path_graphs}/../index.php <<_END
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta http-equiv="Content-Language" content="ru">
<meta http-equiv="Content-Type" content="text/html; charset=koi8r">
<title> Graphs ${1}</title></head>
<body>
<H2>Zabbix server: <a href=${http}://${host}>${host}</a></H1>

<h2>Server uptime: <h3>`uptime`</h3></h2>

<h2>Server kern: <h3>`uname -a`</h3></h2>

<h3>`sysctl kern.ipc.shmall`</h3>

<h3>`sysctl kern.ipc.shmmax`</h3>

<h2>Graphics:</h2>

<table border=1>
<tr>
_END
for gr in cpu la;do
	start_get ${gr} &
done
sleep 5 && start_get

And need add job to the cron.

*/10	*	*	*	*	root	/root/graphs.sh >/dev/null 2>&1

This is script generate the static content every 10 min which's you can get from http://host/zabbix/static

You're need add number graphs in the function start_get() :

cpu)
      get_pic ${1} '1 2 3' ;;

And to the cycle for run the function at the background:

for gr in cpu la;do
	start_get ${gr} &
done

Метки: | | | |

Комментариев: 1

  1. 2011-06-12 в 09:55:21 | Nemolis

    It's nice!XDDD

Оставьте комментарий!

Не регистрировать/аноним

Используйте нормальные имена.

Если вы уже зарегистрированы как комментатор или хотите зарегистрироваться, укажите пароль и свой действующий email.
(При регистрации на указанный адрес придет письмо с кодом активации и ссылкой на ваш персональный аккаунт, где вы сможете изменить свои данные, включая адрес сайта, ник, описание, контакты и т.д.)



grin LOL cheese smile wink smirk rolleyes confused surprised big surprise tongue laugh tongue rolleye tongue wink raspberry blank stare long face ohh grrr gulp oh oh downer red face sick shut eye hmmm mad angry zipper kiss shock cool smile cool smirk cool grin cool hmm cool mad cool cheese vampire snake excaim question

(обязательно)