Advertisement
Guest User

Untitled

a guest
Jan 27th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. NAME
  2. Zabbix::Tiny - A small module to eliminate boilerplate overhead when using the Zabbix API
  3.  
  4. VERSION
  5. 0.500
  6.  
  7. SYNOPSIS
  8. use strict;
  9. use warnings;
  10. use Zabbix::Tiny;
  11.  
  12. use Data::Dumper;
  13.  
  14. my $username = 'zabbix_user';
  15. my $password = 'secretpassword';
  16. my $url = 'http://zabbix.domain.com/zabbix/api_jsonrpc.php';
  17.  
  18. my $zabbix = Zabbix->new(
  19. server => $url,
  20. password => $password,
  21. user => $username
  22. );
  23.  
  24. my $hosts = $zabbix->do(
  25. 'host.get', # First argument is the Zabbix API method
  26. output => [qw(hostid name host)], # Remaining paramters to 'do' are the params for the zabbix method.
  27. hostids => [27,30]
  28. monitored => 1,
  29. limit => 2,
  30. ## Any other params desired
  31. );
  32.  
  33. print Dumper $hosts;
  34.  
  35. DESCRIPTION
  36. This module functions as a simple wrapper to eliminate boilerplate that might otherwise need to be created when interfacing with the Zabbix API.
  37. Login to the Zabbix servre is handled with the constructor. Beyond that, the primary method is the "do" method. The user.logout method is
  38. implemented in the object deconstructor as well, so there should be no need to explicity logout of zabbix.
  39.  
  40. METHOD
  41. my $zabbix = new( server => $url, password => $password, user => $username);
  42. The constructor requires server, user, and password. It will create the zabbix object, and log in to the server all at once.
  43.  
  44. my $hosts = $zabbix->do('zabbix.method', %params);
  45. This will execute any defined zabbix method, with the corresponding params. Refer to the Zabbix manual for a list of available methods. If
  46. the zabbix method is of a *.get flavor, the return is an arrayref data structure containing the response from the zabbix server.
  47.  
  48. my $verbose = $zabbix->last_response;
  49. Communication with the zabbix server is done via the "LWP" module. The "do" method contains a very succinct array ref that should contain
  50. only the data needed for interacting with the zabbix server. The "last_response" argument returns the LWP "HTTP::Response" object, which may
  51. be useful for troubleshooting.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement