Ad Widget

Collapse

Add a host to a network map via Zabbix API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sire
    Senior Member
    • Jul 2010
    • 210

    #1

    Add a host to a network map via Zabbix API

    Hi

    I'm trying to add a host to a network map via Zabbix API. The request is performed without error, but the host doesn't appear on the map, neither does Zabbix database table sysmaps_elements change.

    JSON query:
    Code:
    {
       "params" : {
          "selements" : [
             {
                "iconid_off" : "11",
                "iconid_unknown" : "0",
                "label_location" : "0",
                "x" : 400,
                "elementid" : "10101",
                "sysmapid" : "7",
                "iconid_on" : "0",
                "y" : 300,
                "iconid_disabled" : "0",
                "url" : "",
                "label" : "Маршрутизатор\n{IPADDRESS}",
                "elementtype" : "0",
                "iconid_maintenance" : "0"
             }
          ],
          "sysmapid" : "7"
       },
       "auth" : "4e7f3c8ff1716f84f7d3e8eef536853f",
       "jsonrpc" : "2.0",
       "method" : "map.update",
       "id" : 7
    }
    JSON result:
    Code:
    {
       "sysmapids" : [
          "7"
       ]
    }
    What am I doing wrong? Is the ability to modify map objects implemented in the API, or is there another way of doing this?

    Zabbix version is 1.8.5rc1.x-18700.
    Regards,
    Sergey Syreskin

    Monitored hosts: 2646 / Active items: 23604 / Server performance: 765.74

    Temporary out of Zabbix business
  • Konstantin II
    Junior Member
    • Oct 2010
    • 2

    #2
    sire, what tool are you using to send the request? Is the JSON you've posted the same as being submitted to server?

    There were issues, when some tools truncated the squqare brackets and, because of that, element was not added.

    Comment

    • sire
      Senior Member
      • Jul 2010
      • 210

      #3
      Originally posted by Konstantin II
      sire, what tool are you using to send the request?
      Konstantin II, I am using JSON::RPC::Client perl module http://www.cpan.org/modules/by-modul...PC-0.96.tar.gz

      Originally posted by Konstantin II
      Is the JSON you've posted the same as being submitted to server?
      Yes, it is the same.

      Originally posted by Konstantin II
      There were issues, when some tools truncated the squqare brackets and, because of that, element was not added.
      I guess it's another issue, because the brackets are in place, if my understanding of https://support.zabbix.com/browse/ZBX-3685 is correct.
      Regards,
      Sergey Syreskin

      Monitored hosts: 2646 / Active items: 23604 / Server performance: 765.74

      Temporary out of Zabbix business

      Comment

      • sire
        Senior Member
        • Jul 2010
        • 210

        #4
        Konstantin II, please note, that I'm using map.update, not map.create method. And if you look at the implementation of the former one, you will notice, that it doesn't deal with selements at all.
        Regards,
        Sergey Syreskin

        Monitored hosts: 2646 / Active items: 23604 / Server performance: 765.74

        Temporary out of Zabbix business

        Comment

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

          #5
          Originally posted by Konstantin II
          There were issues, when some tools truncated the squqare brackets and, because of that, element was not added.
          just a quick note that it was my pre-processing, not the tool (zabcon) which nuked the square brackets
          Zabbix 3.0 Network Monitoring book

          Comment

          • Konstantin II
            Junior Member
            • Oct 2010
            • 2

            #6
            Originally posted by sire
            Konstantin II, please note, that I'm using map.update, not map.create method. And if you look at the implementation of the former one, you will notice, that it doesn't deal with selements at all.
            sire, you are right, sorry. I've tried a request with the same data you have, and it appears, that zabbix 1.8 has limited possibillities of interacting with maps over API. For example, you can update only map properties, but not elements - that is why your element is not being created.

            API will have full map support in 2.0. Sorry for the confusion.

            Comment

            • Nespa
              Junior Member
              • Sep 2012
              • 2

              #7
              Using Perl module https://github.com/mikeda/ZabbixAPI I've create a numer of hosts, which now should land on a series of maps.
              After a

              Code:
               $za->map_create(
                              [
                                      {
                                      name    => 'mapname',
                                      width   => 800,
                                      height  => 600,
                                      label_type => 0,
                                      }
                              ]
                      );
              I run an update to add a host:
              $sysmapid is provided with a map_get()
              $hostid points to an existing host, $x and $y position on the map.
              Code:
              $za->map_update (
                              {
                               sysmapid => $sysmapid,
                               selements =>[
                                               {
                                               sysmapid => $sysmapid,
                                               iconid_on => 128,
                                               iconid_off => 128,
                                               iconid_maintenance => 128,
                                               iconid_disabled => 128,
                                               x => $x,
                                               y => $y,
                                               elementid => $hostid,
                                               elementtype => 0,
                                               label => '{HOST.NAME}'
                                              },
                                       ] # selements []
                               } # map_update{}
                              ); # map_update()
              Works fast and as expected: I have a map with 1 host element. Problem is when I add more hosts/selements: it seems to overwrite the map data of the previous host/selement.

              The [] brackets in selements are positional, how can I add a new host/selement after the last so I don't overwrite the data?

              My network maps have different amount of hosts, so create the maps with the variable number of hosts/selements would be troublesome to do.

              Comment

              • Pavels
                Member
                • Oct 2011
                • 83

                #8
                To manipulate elements on a map in 1.8 you can use the map.addElements, map.updateElements and map.deleteElements. They are not documented, so you'll need to have a look at the source code, to see how they work.

                Comment

                • Nespa
                  Junior Member
                  • Sep 2012
                  • 2

                  #9
                  $ tar zxvf zabbix-2.0.2.tar.gz
                  $ cd zabbix-2.0.2/
                  $ grep -i addselements `find .`

                  Doesn't find addElements, neither in zabbix 2.1.0 download.

                  Comment

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

                    #10
                    Originally posted by Nespa
                    $ tar zxvf zabbix-2.0.2.tar.gz
                    $ cd zabbix-2.0.2/
                    $ grep -i addselements `find .`

                    Doesn't find addElements, neither in zabbix 2.1.0 download.
                    looks like in 2.0 it's createSelements
                    unfortunately manual doesn't seem to know anything about that either...
                    Zabbix 3.0 Network Monitoring book

                    Comment

                    • Pavels
                      Member
                      • Oct 2011
                      • 83

                      #11
                      Originally posted by Nespa
                      $ tar zxvf zabbix-2.0.2.tar.gz
                      $ cd zabbix-2.0.2/
                      $ grep -i addselements `find .`

                      Doesn't find addElements, neither in zabbix 2.1.0 download.
                      In 2.0 it's map.createSelements, map.updateSelements and map.deleteSelements.

                      Comment

                      Working...