Ad Widget

Collapse

Adding Items to Templates using the API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • markrs
    Junior Member
    • Apr 2015
    • 1

    #1

    Adding Items to Templates using the API

    Is there a way to create an Item using the API and attach it to a specific Template as opposed to a Host? The item.create API seems to require a hostid and the templateid property is listed as read-only.

    The only other option I can see is to create the Items through the API attached to a specific host and then use the web interface to copy them over to the template.

    If anyone has any ideas on how this could be done through the API I'd appreciate the help. (I'm using Zabbix 2.2.2.)
  • timbo
    Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2013
    • 50

    #2
    Hi markrs,

    I just tested this with my home grown API wrapper and it does work. Just use the Template Id in place of the Host Id in the "Item.Create" method. For example:

    {"jsonrpc": "2.0","method": "item.create","params": {"hostid":"*TEMLATE_ID_GOES_HERE*","name":" ... etc ...

    From what I understand Hosts and Templates are almost identical (from a database perspective), and I think are even stored in the same database table side by side.

    As a quick exercise, go to Configuration->Templates in the web front end, then mouse over the URL for the "Template Name", then the "Items", you'll notice they have the same ID number. See the image attached.

    Click image for larger version

Name:	tempid_vs_hostid.jpg
Views:	1
Size:	58.9 KB
ID:	312978

    I'm using 2.4.4 (just upgraded from 2.2), I believe this should work for you too.

    Good luck!

    -Timbo

    Comment

    Working...