Ad Widget

Collapse

Zabbix API object service.getsla

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dirckcopeland
    Member
    • Oct 2013
    • 50

    #1

    Zabbix API object service.getsla

    Using:
    Zabbix server v2.4.7 (revision 56694) (12 November 2015)



    I'm am seeing unexpected return values in the output from my perl script that is supposed to return the percentage uptime and other values. I'm able to access the API but with unexpected results. I'm sure it's just a syntax issue in the parms section of the code but not sure the correct syntax. If you have suggestion on the correct syntax, I would appreciate it. Here is the perl script:
    Code:
    #!c:\perl64\bin\perl
    
    use 5.010;
    use strict;
    use warnings;
    use JSON::RPC::Client;
    use Data::Dumper;
    
    # Authenticate yourself
    my $client = new JSON::RPC::Client;
    my $url = 'http://#######/zabbix/api_jsonrpc.php';
    my $response;
    my $json = {
    jsonrpc=> '2.0',
    method => 'service.getsla',
    params => 
    {
    serviceids => "75",
    intervals => ["1471824000", "1472428800"],
    },
    id => 1,
    auth => "XXXXXXXXXXXXXXXXXXXXXXXXXX",
    };
    
    $response = $client->call($url, $json);
    print Dumper($response);
    printf "%s\n",$respon
    I'm expecting to get back the percentage uptime between

    intervals => ["1471824000", "1472428800"],
    August 22nd thru August 29th, but it returns 100 instead of 99.73 that is displayed in the Monitoring/IT Services screen in the Zabbix Frontend. It is also returning "1" in the from and to fields of the output.

    Code:
    $VAR1 = bless( {
                     'content' => {
                                    'jsonrpc' => '2.0',
                                    'result' => {
                                                  '75' => {
                                                            'problems' => [],
                                                            'status' => '0',
                                                            'sla' => [
                                                                       {
                                                                         'problemTime' => 0,
                                                                         'okTime' => 0,
                                                                         'downtimeTime' => 0,
                                                                         'sla' => 100,
                                                                         'from' => '1',
                                                                         'to' => '1'
                                                                       },
                                                                       {
                                                                         'okTime' => 0,
                                                                         'problemTime' => 0,
                                                                         'to' => '1',
                                                                         'downtimeTime' => 0,
                                                                         'sla' => 100,
                                                                         'from' => '1'
                                                                       }
                                                                     ]
                                                          }
                                                },
                                    'id' => 1
                                  },
                     'is_success' => 1,
                     'jsontext' => '{"jsonrpc":"2.0","result":{"75":{"status":"0","problems":[],"sla":[{"from":"1","to":"1","sla":100,"okTime":0,"problemTime":0,"downtimeTime":0},{"from":"1","to":"1","sla":100,"okTime":0,"problemTime":0,"downtimeTime":0}]}},"id":1}',
                     'version' => 0
                   }, 'JSON::RPC::ReturnObject' );
    JSON::RPC::ReturnObject=HASH(0x3714dd0
    Any thoughts are appreciated.
  • dirckcopeland
    Member
    • Oct 2013
    • 50

    #2
    Zabbix API object service.getsla

    OK, feeling silly now, no sooner did I post this and the next thing I tried worked. Here is the correct code for what I was trying to do when extracting the SLA information for the week period
    Code:
    #!c:\perl64\bin\perl
    
    use 5.010;
    use strict;
    use warnings;
    use JSON::RPC::Client;
    use Data::Dumper;
    
    # Authenticate yourself
    my $client = new JSON::RPC::Client;
    my $url = 'http://XXXXXXXX/zabbix/api_jsonrpc.php';
    my $response;
    my $json = {
    jsonrpc=> '2.0',
    method => 'service.getsla',
    params => 
    {
    serviceids => "75",
    intervals => [
    		{
    			from => "1471824000", 
    			to => "1472428800",
    		}
    	],
    },
    id => 1,
    auth => "XXXXXXXXXXXXXXXXXXXXXXXXXX",
    };
    
    $response = $client->call($url, $json);
    print Dumper($response);
    printf "%s\n",$response;

    Here is the output from the script:
    Code:
    $VAR1 = bless( {
                     'jsontext' => '{"jsonrpc":"2.0","result":{"75":{"status":"0","problems":[],"sla":[{"from":"1471824000","to":"1472428800","sla":99.76917989418,"okTime":603404,"problemTime":1396,"downtimeTime":0}]}},"id":1}',
                     'content' => {
                                    'jsonrpc' => '2.0',
                                    'id' => 1,
                                    'result' => {
                                                  '75' => {
                                                            'status' => '0',
                                                            'problems' => [],
                                                            'sla' => [
                                                                       {
                                                                         'problemTime' => 1396,
                                                                         'from' => '1471824000',
                                                                         'downtimeTime' => 0,
                                                                         'okTime' => 603404,
                                                                         'sla' => '99.76917989418',
                                                                         'to' => '1472428800'
                                                                       }
                                                                     ]
                                                          }
                                                }
                                  },
                     'version' => 0,
                     'is_success' => 1
                   }, 'JSON::RPC::ReturnObject' );
    JSON::RPC::ReturnObject=HASH(0x367c600)
    Last edited by dirckcopeland; 19-10-2016, 04:29. Reason: Need to add the output from the code

    Comment

    Working...