Ad Widget

Collapse

How can I disable all triggers created by trigger prototype?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zkry.akgul
    Junior Member
    • Sep 2022
    • 4

    #1

    How can I disable all triggers created by trigger prototype?

    I have 30 hosts in my Zabbix. All nodes have the "Docker by Zabbix Agent 2" template. A trigger prototype in this template named "Container {#NAME}: Container has been stopped with error code". We use Kubernetes on our hosts so containers continuously stop but we don't care about it. But Zabbix keeps disturbing us with the "Container something has been stopped with error code" alert. I want to disable all these triggers. I Tried the disabling trigger prototype from UI. I also tried clicking the "Create disabled" button. But the old triggers are still enabled and I cannot disable them manually because there are more than 1000 triggers across all hosts. So how can I disable them in an easy way?

    My Zabbix version: 6.2.3
  • cyber
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Dec 2006
    • 4807

    #2
    you can go to config->hosts-> triggers (on a random host) -> clear all fields and enter only your trigger name (or part of it) in selection... you should get all your instances... and then do mass update...

    I think discovery has to run again after you have changed template (and prototypes), so maybe waiting a bit or forcing discovery again will change the triggers?​

    Comment

    • zkry.akgul
      Junior Member
      • Sep 2022
      • 4

      #3
      I tried this already but there is only 50 Item per page and as I said there are more than 1000 record(I don't know the exact count because Zabbix just says "There are 1000+ records"). Is there any way to execute mass update on all records?

      Comment

      • zkry.akgul
        Junior Member
        • Sep 2022
        • 4

        #4
        I solved this with help of ChatGPT
        It gives me a python script and after a few modifications, it did the work!

        Code:
        import requests
        import json
        
        # Set the Zabbix API URL and credentials
        zabbix_url = 'http://zabbix.example.com/api_jsonrpc.php'
        zabbix_username = 'your_username'
        zabbix_password = 'your_password'
        
        # Define a function to authenticate with the Zabbix API and retrieve a session ID
        def zabbix_login():
            auth_data = {
                'jsonrpc': '2.0',
                'method': 'user.login',
                'params': {
                    'user': zabbix_username,
                    'password': zabbix_password,
                },
                'id': 1,
            }
            auth_response = requests.post(zabbix_url, json=auth_data).json()
            return auth_response['result']
        
        # Define a function to disable all triggers associated with the specified trigger prototype name
        def disable_triggers(trigger_proto_name):
            # Authenticate with the Zabbix API
            session_id = zabbix_login()
        
            # Get the IDs of all hosts with the Docker by Zabbix Agent 2 template
            host_ids_data = {
                'jsonrpc': '2.0',
                'method': 'host.get',
                'params': {
                    'output': ['hostid'],
                    'filter': {
                        'template': [
                            'Docker by Zabbix Agent 2',
                        ],
                    },
                },
                'auth': session_id,
                'id': 2,
            }
            host_ids_response = requests.post(zabbix_url, json=host_ids_data).json()
            print(host_ids_response)
        
            # For each host ID, get the IDs of all triggers associated with the specified trigger prototype name
            for host_data in host_ids_response['result']:
                trigger_proto_data = {
                    'jsonrpc': '2.0',
                    'method': 'trigger.get',
                    'params': {
                        'output': ['triggerid'],
                        'selectItems': ['itemid'],
                        'search': {
                            'description': [trigger_proto_name],
                        },
                        'searchWildcardsEnabled': 1,
                        'hostids': host_data['hostid'],
                    },
                    'auth': session_id,
                    'id': 3,
                }
                trigger_proto_response = requests.post(zabbix_url, json=trigger_proto_data).json()
                print(trigger_proto_response)
                # For each trigger ID, disable the trigger
                for trigger_data in trigger_proto_response['result']:
                    trigger_id = trigger_data['triggerid']
                    trigger_update_data = {
                        'jsonrpc': '2.0',
                        'method': 'trigger.update',
                        'params': {
                            'triggerid': trigger_id,
                            'status': 1,
                        },
                        'auth': session_id,
                        'id': 4,
                    }
                    trigger_update_response = requests.post(zabbix_url, json=trigger_update_data).json()
        
        
                    if 'error' in trigger_update_response:
                        print(trigger_update_response)
                    else:
                        print(f"The trigger with id:{trigger_id} has been disabled!")
        
        if __name__ == '__main__':
            trigger_name = '*Container has been stopped with error code*'
            disable_triggers(trigger_name)

        Comment

        • cyber
          Senior Member
          Zabbix Certified SpecialistZabbix Certified Professional
          • Dec 2006
          • 4807

          #5
          Originally posted by zkry.akgul
          I tried this already but there is only 50 Item per page and as I said there are more than 1000 record(I don't know the exact count because Zabbix just says "There are 1000+ records"). Is there any way to execute mass update on all records?
          You can change that.. Admin-> general ->GUI and there is limit for returned results. and then there's User profile and "rows per page" setting..
          And even with default settings you can just select all, navigate to next page, select all again... etc... it will remember all those selected hosts...
          Last edited by cyber; 07-03-2023, 09:58.

          Comment

          • marco_a
            Junior Member
            • Mar 2023
            • 7

            #6
            Hi, I have the same problem with network device templates.
            I tried the excellent solution with python script, but the template filter doesn't seem to work, it takes out the ID of all the configured hosts. Unfortunately I know little about Python and I'm now starting to use the Zabbix API. Any suggestions?
            Thank you

            Comment

            Working...