Advertisement
Guest User

Untitled

a guest
Oct 28th, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. #! /usr/bin/env ruby
  2.  
  3. require 'zabbixapi'
  4. require 'yaml'
  5. require 'socket'
  6. require 'time'
  7.  
  8. # ZABBIX CONFIGURATION
  9. config = YAML.load(File.read('/etc/zabbix/scripts/.zabbix/config.yml'))
  10. zabbix_url = config['URL']
  11. zabbix_id = config['USER']
  12. zabbix_passwd = config['PASSWORD']
  13.  
  14. # ZABBIX AUTHENTICATION
  15. zbx = ZabbixApi.connect(
  16. url: zabbix_url,
  17. user: zabbix_id,
  18. password: zabbix_passwd
  19. )
  20.  
  21. # Create time_from and time_till
  22. now = Time.now.strftime('%Y/%m/%d %H:%M:%S')
  23. before = (Time.now - 180).strftime('%Y/%m/%d %H:%M:%S')
  24. till = Time.parse(now)
  25. from = Time.parse(before)
  26. hostname = Socket.gethostname
  27.  
  28. zbx.query(
  29. method: 'item.get',
  30. params: {
  31. filter: {
  32. host: hostname
  33. },
  34. itemids: '23663'
  35. }
  36. )
  37.  
  38. trends = zbx.query(
  39. method: 'history.get',
  40. params: {
  41. itemids: item_id,
  42. time_from: from,
  43. time_till: till,
  44. output: 'extend'
  45. }
  46. )
  47.  
  48. p trends
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement