Skip to content

Instantly share code, notes, and snippets.

@tsubauaaa
Last active October 19, 2015 10:13
Show Gist options
  • Save tsubauaaa/7004cbcf5186888112eb to your computer and use it in GitHub Desktop.
Save tsubauaaa/7004cbcf5186888112eb to your computer and use it in GitHub Desktop.
zabbix api history value get before 5m
#! /usr/bin/env ruby
require "zabbixapi"
require "yaml"
require "time"
config = YAML.load(File.read(".zabbix/config.yml"))
zabbix_url = config['URL']
zabbix_user = config['USER']
zabbix_passwd = config['PASSWORD']
now = Time.now.strftime("%Y/%m/%d %H:%M:%S")
before = (Time.now - 300).strftime("%Y/%m/%d %H:%M:%S")
time_till = Time.parse(now)
time_from = Time.parse(before)
zbx = ZabbixApi.connect(
:url => zabbix_url ,
:user => zabbix_user ,
:password => zabbix_passwd
)
history = zbx.query(
:method => "history.get",
:params => {
# :history => 0,
:itemids => ["12345"],
:time_from => time_from.to_i,
:time_till => time_till.to_i,
:output => "extend"
}
)
val = history[0]['value']
puts val
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment