Advertisement
kazoda

Zabbix history max value 2

Jul 27th, 2014
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash
  2.  
  3. start_daytime=$(date --date "$1 00:00:00" +%s)
  4. end_daytime=$(date --date "$2 00:00:00" +%s)
  5. itemid=${3:-23347}
  6.  
  7. sql_string="select history.itemid, items.name, history.clock, history.value \
  8.   from history INNER JOIN items ON history.itemid=items.itemid \
  9.   where value = ( select max(value) from history where itemid=$itemid and \
  10.   clock >= $start_daytime and clock <= $end_daytime) \
  11.   and history.itemid=$itemid and history.clock >= $start_daytime \
  12.   and history.clock <= $end_daytime\G"
  13.  
  14. for f in $(mysql -B -s -r -u root -p zabbix -e "$sql_string" | sed -e '/^\*.*\*$/d' -e 's/ //g')
  15. do
  16.    if [ ${f%:*} = "clock" ]; then
  17.       date_str=$(date --date @${f##*:})
  18.       echo ${f%:*}:${date_str}
  19.    else
  20.       echo $f
  21.    fi
  22. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement