Ad Widget

Collapse

Is possible to run trigger using python script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lkip912
    Junior Member
    • Dec 2019
    • 8

    #1

    Is possible to run trigger using python script?

    Hi folks, I have python script which is downloading and parsing some files. In these files I am looking for some string. I would like to ask if there is any way how to connect it to zabbix. I would like to run trigger in case that script will find string which I am looking for. Is there any solution how to do it? Thank you in advance.
  • Markku
    Senior Member
    Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
    • Sep 2018
    • 1781

    #2
    Hi, you can create an item of type Zabbix trapper, and send data to it with for example https://github.com/markkuleinio/zbxsend. Then you can define suitable trigger in Zabbix.

    Alternatively, if your script can do its thing fast (like in two seconds or faster), then you can use UserParameters and call your script directly in a Zabbix agent item.

    Markku

    Comment

    • lkip912
      Junior Member
      • Dec 2019
      • 8

      #3
      Great, thank you for your answer, but I have problem with sending data using zbxsend. I always get error message
      ERROR:zbxsender:Wrong zabbix response
      Here is line from script
      HTML Code:
      send_to_zabbix([Metric('192.168.1.77', 'trapx', 1)], '192.168.0.100', 10050)
      192.168.0.100 zabbix server
      192.168.1.77 my pc

      Screen of settings

      Click image for larger version  Name:	tz.jpg Views:	0 Size:	37.9 KB ID:	395111

      I have checked zabbix_server.log, but I didn't find any information about possible problem. I wanted to try zabbix_sender to send some test data, but I don't know how to get it. In documentation, there is written that is located in bin folder, but I don't have it, and I didn't find any more information about this tool. Could someone help me, where could be a problem or how to debug it?
      Last edited by lkip912; 07-02-2020, 15:38.

      Comment

      • Markku
        Senior Member
        Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
        • Sep 2018
        • 1781

        #4
        Hi, you have incorrect port 10050 there, should be 10051 (= the port Zabbix server listens to, not the Zabbix agent port). Just delete the argument, it defaults to 10051.

        Markku

        Comment

        • Markku
          Senior Member
          Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
          • Sep 2018
          • 1781

          #5
          About Zabbix sender, it is a separate package "zabbix-sender" (at least in Debian).

          Markku

          Comment

          • lkip912
            Junior Member
            • Dec 2019
            • 8

            #6
            Thank you very much, you are great! The port was problem. In the list of hosts there is interface 127.0.0.1:10050, this is why I put there wrong port. I have also found zabbix-sender, I was looking for zabbix_sender according to documentation.

            However I have one more problem. I can successfully send data by zabbix-sender with this command:
            Code:
            zabbix_sender -z 192.168.0.100 -s "Zabbix server" -k "trapx" -o "asdf"
            but with this line in script it doesn't work (0 processed)
            Code:
            send_to_zabbix([Metric('Zabbix server', 'trapx', 'asdf')], '192.168.0.100', 10051)
            DEBUG:zbxsender:Got response from Zabbix: {'response': 'success', 'info': 'processed: 0; failed: 0; total: 0; seconds spent: 0.000024'}
            INFO:zbxsender: processed: 0; failed: 0; total: 0; seconds spent: 0.000024
            Could you help me? I think it is again some small problem, but I am not able to find it. Thank you in advance.
            Last edited by lkip912; 10-02-2020, 10:35.

            Comment

            • Markku
              Senior Member
              Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
              • Sep 2018
              • 1781

              #7
              So the response is success, 0 failed, but also 0 processed? Is "Zabbix server" host enabled anyway? And you see the zabbix_sender data in Latest data?

              Markku

              Comment

              • lkip912
                Junior Member
                • Dec 2019
                • 8

                #8
                Yes, it is enabled. With zabbix_sender I see data in latest data, everything works. However with python script it doesn't work.

                Comment

                • Markku
                  Senior Member
                  Zabbix Certified SpecialistZabbix Certified ProfessionalZabbix Certified Expert
                  • Sep 2018
                  • 1781

                  #9
                  What is your Python version? I have modified the code with Python 3 in mind (and It works for me<tm> ), with legacy Python (2.x) I don't know how it actually works. (In the latter case you may want to try the original author's code in https://github.com/pistolero/zbxsend)

                  You may want to take some packet capture as well to see the actual content of the packets.

                  Markku

                  Comment

                  Working...