Ad Widget

Collapse

Zabbix 1.8 API and Perl

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stu42j
    Junior Member
    • Feb 2010
    • 9

    #1

    Zabbix 1.8 API and Perl

    Does anyone else access the Zabbix API from Perl. Do most people use one of the JSON-RPC libraries from CPAN?

    I've been working on a simple API wrapper module in Perl. Would there be any interest in sharing or development?
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #2
    I can help collaborate with you if you'd like. Also if you would like I can host your code along side the Ruby Zabbix API libraries.
    RHCE, author of zbxapi
    Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
    Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

    Comment

    • stu42j
      Junior Member
      • Feb 2010
      • 9

      #3
      What I have is just a simple wrapper, it doesn't do any verification of API methods or attributes. Since it meets my needs, I probably won't be developing it any further. I'm happy to share it as an example, though.

      Perl wrapper for Zabbix API. Contribute to sjohnston/Net-Zabbix development by creating an account on GitHub.

      Comment

      • svenw
        Junior Member
        • May 2008
        • 26

        #4
        hi!

        thanks for posting this. in the last hours i just figured out how to handle this json stuff myself, but a ready module is very welcome ;-)

        thanks,
        sven

        Comment

        • marcel
          Senior Member
          Zabbix Certified Specialist
          • Oct 2010
          • 112

          #5
          Stuart, would it be possible to post a simple code how to use the library?
          It would be very much appreciated!

          Thanks,
          Marcel
          Zabbix Certified Specialist for Large Environments since 12/2010

          Comment

          • stu42j
            Junior Member
            • Feb 2010
            • 9

            #6
            Sure, here is a sample usage:

            Code:
            use Net::Zabbix;
            
            my $url = 'http://192.168.0.1';
            my $z = Net::Zabbix->new($url, $user, $password);
            my $trigger = $z->get('trigger', { triggerids => [$trigger_id] });
            I'm not using Zabbix anymore so I don't know if the module works with 1.8.

            Comment

            • marcel
              Senior Member
              Zabbix Certified Specialist
              • Oct 2010
              • 112

              #7
              Thanks Stu!

              I can confirm that the conde works with 1.8.3 - actually I am alerady using it extensively for some auto-discovery of items on low level and additn ght items into Zabbix.

              What do you use instead Zabbix?
              Zabbix Certified Specialist for Large Environments since 12/2010

              Comment

              • KHoos
                Junior Member
                • Nov 2010
                • 4

                #8
                Zabbix 1.8 API and Perl

                I'm trying the given Perl api and getting very empty answers. From viewing the request and answer with tcpdump it looks all valid, I just get empty answers.

                Relevant perl code:

                Code:
                my $zabbixsession = Net::Zabbix->new($server,$user,$pass);
                my $sslgroupobject = $zabbixsession->get('host', { output => 'extend', filter => { name => [ $hostname] }});
                print Dumper($sslgroupobject);
                The dumper output is always:

                Code:
                $VAR1 = {
                          'jsonrpc' => '2.0',
                          'id' => 2,
                          'result' => []
                        };
                looking at the request/reply traffic with tcpdump shows reasonable values:

                Code:
                User-Agent: Net::Zabbix
                Content-Type: application/json-rpc
                Content-Length: 120
                {"auth":"197822c2af350d08c4fec02a41c12302","params":{"output":"extend"},"jsonrpc":"2.0","id":2,"method":"hostgroup.get"}
                HTTP/1.1 200 OK
                Date: Fri, 05 Nov 2010 14:50:07 GMT
                Server: Apache/2.2.3 (Scientific Linux)
                X-Powered-By: PHP/5.1.6
                Set-Cookie: zbx_sessionid=197822c2af350d08c4fec02a41c12302
                Content-Length: 36
                Connection: close
                Content-Type: text/html; charset=UTF-8
                {"jsonrpc":"2.0","result":[],"id":2}
                The earlier user.authenticate call goes through fine.

                I have tried several types of filters / non-filters or other parameters.

                Update: it helps when the api-user has access to the group(s) you want data from.
                Last edited by KHoos; 05-11-2010, 17:33. Reason: Thanking the teddybear

                Comment

                • marcel
                  Senior Member
                  Zabbix Certified Specialist
                  • Oct 2010
                  • 112

                  #9
                  try "pattern" instead of "filter"
                  Zabbix Certified Specialist for Large Environments since 12/2010

                  Comment

                  • KHoos
                    Junior Member
                    • Nov 2010
                    • 4

                    #10
                    Now to get the templates linked to a host

                    Succes with that bit (just make sure the API user has actual access to the object).

                    Now for my next issue: I get a list of hosts. Now I want to know the linked templates per host.

                    I can get all templates (that I have access to), but I can't filter a selection of templates per host yet.

                    Update:
                    Bug in the documentation: using select_templates with host.get (and NOT selectParentTemplates) I can fetch the templates for each host.
                    Last edited by KHoos; 05-11-2010, 18:41. Reason: Found it

                    Comment

                    • richlv
                      Senior Member
                      Zabbix Certified Trainer
                      Zabbix Certified SpecialistZabbix Certified Professional
                      • Oct 2005
                      • 3112

                      #11
                      Originally posted by KHoos
                      Update:
                      Bug in the documentation: using select_templates with host.get (and NOT selectParentTemplates) I can fetch the templates for each host.
                      hmm. is that some older version of the api, maybe ? latest version should work as documented
                      Zabbix 3.0 Network Monitoring book

                      Comment

                      • KHoos
                        Junior Member
                        • Nov 2010
                        • 4

                        #12
                        Zabbix 1.8 API and Perl

                        Originally posted by richlv
                        hmm. is that some older version of the api, maybe ? latest version should work as documented
                        Still running 1.8.2. Which may be the cause of other problems.

                        Comment

                        • richlv
                          Senior Member
                          Zabbix Certified Trainer
                          Zabbix Certified SpecialistZabbix Certified Professional
                          • Oct 2005
                          • 3112

                          #13
                          oh. i would suggest to wait for upcoming 1.8.11 and upgrading to that one then
                          Zabbix 3.0 Network Monitoring book

                          Comment

                          Working...