Ad Widget

Collapse

How to create and store custom events in our Zabbix instance?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • olie480
    Junior Member
    • Sep 2024
    • 4

    #1

    How to create and store custom events in our Zabbix instance?

    I wanted to track some custom metrics into our Zabbix instance now that I am familiar with the graphs, etc and I want to start stacking graphs on top of each other, during certain events to get the whole story on why metrics are going up, etc. We are using Zabbix 6.4, and I have a couple of general Postman requests interacting with our Zabbix instance API, mostly just getting the host ID, 1m Load Average, etc. but now what I want to do is start recording certain events in our Zabbix instance for our hosts. The first custom event that I want to track is whether a process is currently running. This can be a very basic 1, or 0 value, just so I can get my feet wet with creating custom metrics. So when the process starts, I will record a 1, and then after the process has finished, I'll record a 0.

    With that out of the way, is there any documentation where I can see how to create these custom events for a host (we have about 100 hosts we're managing)? We are a PHP shop, so any examples would be great, or if there are any libraries already created for this, that would be great too. I am hoping we can just create the custom events through an API request, but if I have to set up the custom event inside Zabbix first before recording the events, that's fine too. I just need a jumping off point right now. I came from a NewRelic shop, and NewRelic had a PHP extension I could use to create these custom events easily. Also, I tried ChatGPT to see if I could get anywhere, but it wasn't any help with this

    Thanks in advance!
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    You can use this functionality here



    Comment

    • olie480
      Junior Member
      • Sep 2024
      • 4

      #3
      Thanks Hamardaban. So it looks like in Zabbix 7.0, these custom events CAN be sent through the API, correct? Since I am using Zabbix 6.4 the `zabbix_sender` needs to be use. I tried using the `zabbix_sender` but it kept giving me the following error:

      $: `zabbix_sender -z xxx.xxx.xxx.xxx -s "mydomain.com" -k "custom.event.wordpress" -o "WordPress Plugin Updated"`

      ```
      Response from "xxx.xxx.xxx.xxx:10051": "processed: 0; failed: 1; total: 1; seconds spent: 0.000299"
      sent: 1; skipped: 0; total: 1
      ```
      I also tried zabbix_sender with the -vv command and get this:

      ```
      zabbix_sender [1408714]: DEBUG: In zbx_connect_to_server() [xxx.xxx.xxx.xxx]:10051 [timeout:60, connection timeout:3]
      zabbix_sender [1408714]: DEBUG: In zbx_is_ip4() ip:'xxx.xxx.xxx.xxx'
      zabbix_sender [1408714]: DEBUG: End of zbx_is_ip4():SUCCEED
      zabbix_sender [1408714]: DEBUG: answer [{"response":"success","info":"processed: 0; failed: 1; total: 1; seconds spent: 0.000244"}]
      Response from "xxx.xxx.xxx.xxx:10051": "processed: 0; failed: 1; total: 1; seconds spent: 0.000244"
      sent: 1; skipped: 0; total: 1
      ```


      One thing I found odd about the zabbix_sender command, is that it doesn't need a key or secret or anything to send to the trapper event. So can I even run this command on my hosts? or does this command need to be run on the actual server where Zabbix is running?

      Thanks!
      Last edited by olie480; 26-09-2024, 18:34.

      Comment

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

        #4
        if sending fails, verify, if all the necessary things are in place... you have a host "mydomain.com", that host has item with a key "custom.event.wordpress" and it is of correct type (text/log/character)
        If your configured host is using encrypted comms and no plain connections are allowed, then you need that information also with zabbix sender. (--tls.* parameters)...

        You can run zabbix_sender whereever you need. all you need is connection to the server and all correct parameters for the data (host/key)... If a host is monitored by a proxy, then yo need to send data to proxy, not to server.

        Comment

        • olie480
          Junior Member
          • Sep 2024
          • 4

          #5
          Originally posted by cyber
          if sending fails, verify, if all the necessary things are in place... you have a host "mydomain.com", that host has item with a key "custom.event.wordpress" and it is of correct type (text/log/character)
          If your configured host is using encrypted comms and no plain connections are allowed, then you need that information also with zabbix sender. (--tls.* parameters)...

          You can run zabbix_sender whereever you need. all you need is connection to the server and all correct parameters for the data (host/key)... If a host is monitored by a proxy, then yo need to send data to proxy, not to server.
          Thank you! So I tried zabbix_sender again, and when it failed, I looked at the zabbix log on the zabbix server, and it's saying "connection of type "unencrypted" is not allowed for host" so it looks like since we're using encryption, the request can't be made. I have found the parameters to add to zabbix_sender for the psk, but I am having a hard time finding where I can grab the psk identity for the host. I do have a .psk file path. For other's reference, the command I need to run is:

          `zabbix_sender -z 106.73.23.98 -s "host.com" -k "custom.event" -o "Files Updated" --tls-connect psk --tls-psk-identity <psk_identity> --tls-psk-file /etc/z/secret.psk`

          Comment

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

            #6
            It should be in the agent config file. There is a parameter called TLSPSKIdentity
            You can also just point zabbix_sender to agent config file with -c option and it shoudl find all necessary parameters from there.

            Comment

            • olie480
              Junior Member
              • Sep 2024
              • 4

              #7
              Originally posted by cyber
              It should be in the agent config file. There is a parameter called TLSPSKIdentity
              You can also just point zabbix_sender to agent config file with -c option and it shoudl find all necessary parameters from there.
              cyber Amazing! Yep, that definitely worked! I went ahead and just use the `-c` option and the path to the `zabbix_agent2.conf` file and it found everything like you said. Amazing! Thank you!

              Comment

              Working...