Advertisement
Nergalwaja

enable_gui.pl

Feb 11th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.19 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use 5.010;
  4. use strict;
  5. use warnings;
  6. use JSON::RPC::Client;
  7. use Data::Dumper;
  8.  
  9. # Authenticate yourself
  10. my $client = new JSON::RPC::Client;
  11. my $url = 'http://10.10.10.108/zabbix/api_jsonrpc.php';
  12. my $authID;
  13. my $response;
  14.  
  15. my $json = {
  16. jsonrpc => "2.0",
  17. method => "user.login",
  18. params => {
  19. user => "Zapper",
  20. password => "zapper"
  21. },
  22. id => 1
  23. };
  24.  
  25. $response = $client->call($url, $json);
  26.  
  27. # Check if response was successful
  28. die "Authentication failed\n" unless $response->content->{'result'};
  29.  
  30. $authID = $response->content->{'result'};
  31. print "Authentication successful. Auth ID: " . $authID . "\n";
  32.  
  33. # Get list of all hosts using authID
  34.  
  35. $json = {
  36. jsonrpc=> '2.0',
  37. method => 'usergroup.update',
  38. params =>
  39. {
  40. usrgrpid => ['12'],# get only host id and host name
  41. gui_access => '0',        # sort by host name
  42. },
  43. id => 2,
  44. auth => "$authID",
  45. };
  46. $response = $client->call($url, $json);
  47.  
  48. # Check if response was successful
  49. die "host.get failed\n" unless $response->content->{result};
  50.  
  51. print "List of hosts\n-----------------------------\n";
  52. foreach my $host (@{$response->content->{result}}) {
  53. print "Host ID: ".$host->{hostid}." Host: ".$host->{name}."\n";
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement