Ad Widget

Collapse

How to add custom default tags for newly created hosts?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Renjith
    Junior Member
    • Jan 2020
    • 2

    #1

    How to add custom default tags for newly created hosts?

    Hi,

    We are trying to create a custom default tags while creating a new hosts in zabbix. Is there any way to change the settings so that when "create new host" is clicked the tags tab should show as tags:"owner" and value: "syseng".
  • Renjith
    Junior Member
    • Jan 2020
    • 2

    #2
    splitek Can we do changes in the backend and get this done? If yes, please explain..

    Comment

    • tim.mooney
      Senior Member
      • Dec 2012
      • 1427

      #3
      I agree with splitek, there's no current way to do this built in to Zabbix.

      I also wouldn't want to maintain custom changes to the Frontend UI, as it makes the barrier to upgrading much higher, because you have to reapply your customizations after each upgrade.

      What would be fairly straightforward to do is to use the Zabbix API to do this. If I were in your situation, I would look at the host.get() and host.update() functions in the API. You could write a script, in any language you like that has good JSON RPC support, that either adds the tag to a particular host you specify or just finds all hosts (that it has access to) that don't have an "owner" tag already, and updates the host to have that tag with the value you want. With that method, you could automate it so that your "zabbix-set-tag" script is run periodically to "fix up" any hosts that are missing the tag.

      Comment

      • verde
        Member
        • Jul 2021
        • 39

        #4
        Hi, I have a host created via API (host.create) including initial tags.
        I'm trying to add a new tag for a host, but the API call replaces all the 5 old tags with the new one I wanted to add. So instead of having 6 tags, the host ended up with only 1.
        Any suggestions to run the host.update?

        zabbix_server (Zabbix) 6.2.1

        Call:
        url='http://'+ zbxServer +'/zabbix/api_jsonrpc.php';

        Code:
        host.update:
                       data={
                            "jsonrpc": "2.0",
                            "method": "host.update",
                            "params": {
                                "hostid": hostid,
                                "tags": [ {
                                    "tag": "deactivated",
                                    "value": deactivationDate
                                }]
                            },
                            "auth": token,
                            "id": 1
                        }

        Also, I tried to use host.get with "selectTags": "extend", but it brings the tags with an "automatic": "0" in each tag, i.e:

        Code:
        host.get:
        
         "tags": [
              {
                "tag": "type",
                "value": "server",
                "automatic": "0"
              },
              ...
              ...
              {
                "tag": "service",
                "value": "active",
                "automatic": "0"
              }
            ]
        ​
        when I added the new tag to the existing tags and try to host.update, I'm receiving the error:

        Code:
        Reading :  [{'tag": "type","value": "server", "automatic": "0"},.....{"tag":"service","value":"active","automatic":"0"}]
        Append:    [{'tag": "type","value": "server", "automatic": "0"},.....{"tag":"service","value":"active","automatic":"0"}, {"tag": "deactivated", "value": "2022-08-26 20:51:53"}]
        
        host.update:
        
              Error: {'jsonrpc': '2.0', 'error': {'code': -32602, 'message': 'Invalid params.', 'data': 'Invalid parameter "/1/tags/1": unexpected parameter "automatic".'}, 'id': 1}
        ​
        Thanks
        Last edited by verde; 26-08-2022, 20:31.

        Comment

      Working...