Ad Widget

Collapse

Sending custom parameters (or macros) in alerts

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DreamMark
    Junior Member
    • Oct 2014
    • 8

    #1

    Sending custom parameters (or macros) in alerts

    My issue is this. My company has a customer that uses Zabbix. They want Zabbix to be able to interact with the company's internal custom monitoring system.

    The company's internal monitoring system needs to receive certain parameters/codes to alert.

    For example, if Zabbix sends an alert "Free disk space is less than 20% on volume /var/lib/vz" the company's monitoring system needs to receive the code "SBC001" to send its own alert for disk space issues.

    If Zabbix sends an alert for "Web scenario failed" the company's monitoring system needs to receive the code "URL001" to send its own alert for URL issues.

    Is there a way to pass these parameters from Zabbix to the company's monitoring system using SNMP or the Custom Alertscripts option? The internal monitoring system can receive SNMP traps but needs specific parameters to alert.

    I can get a Custom Alertscripts to fire that will interact with the company's internal monitoring system, but not sure how to pass the parameters it needs.

    For example I tried.... inside a bash script called test.sh in the alertscripts directory I put:

    ./script.sh --parameter --message (where parameter would be the custom code the internal monitoring system needs to alert, based on the alarm type). However, I don't know how to pass the custom parameter the internal system needs when Zabbix fires an alert.

    Can anyone point me to an explanation or documentation on how this can be done? Or point me in the right direction.

    Thanks
    Last edited by DreamMark; 24-11-2014, 23:08.
  • BDiE8VNy
    Senior Member
    • Apr 2010
    • 680

    #2
    How about making sure that the alert script gets the respective "code" passed in one of the three parameters (e.g. subject)?

    Another way might be to define a scheme to be recognized by your alert script. E.g. extMonCode(SBC001).
    Your alert script might then parse either a specific or all passed parameter for that construct, extract it when found and finally assembles all information in the right way.

    Comment

    • DreamMark
      Junior Member
      • Oct 2014
      • 8

      #3
      Originally posted by BDiE8VNy
      How about making sure that the alert script gets the respective "code" passed in one of the three parameters (e.g. subject)?

      Another way might be to define a scheme to be recognized by your alert script. E.g. extMonCode(SBC001).
      Your alert script might then parse either a specific or all passed parameter for that construct, extract it when found and finally assembles all information in the right way.
      Thanks for the response BDiE8VNy.

      Yes. I was thinking of using custom macros for notifications (available in version 2.4) and then passing them as one of the three parameters, as you stated.

      However, I'm still trying to figure out how Zabbix would select the right code to send in the notification, based on the type of alert.

      For example. If it's a CPU issue then use code SBC001 and for a DISK issue use code DCS400. And it would run a script:

      Example:
      ./testscript.sh -parameter {$CUSTOM.MACRO} -parameter {HOST.NAME1} -parameter {TRIGGER.NAME}

      Comment

      • BDiE8VNy
        Senior Member
        • Apr 2010
        • 680

        #4
        When these codes have to be defined on trigger level, then either define a proper place within the trigger name or if possible use the description field.
        Otherwise I'd suggest to add these codes on action level but then you'll need at least one action per code (btw, that's how i do it atm).

        You might possibly be interested in ZBXNEXT-1645

        Comment

        • DreamMark
          Junior Member
          • Oct 2014
          • 8

          #5
          Originally posted by BDiE8VNy
          When these codes have to be defined on trigger level, then either define a proper place within the trigger name or if possible use the description field.
          Otherwise I'd suggest to add these codes on action level but then you'll need at least one action per code (btw, that's how i do it atm).

          You might possibly be interested in ZBXNEXT-1645
          Thanks. This was very helpful.

          If I were to add these codes on the action level with one action per code... for the Conditions tab, if I were to set the condition as "Application = CPU", does it mean that action will alert for all the Items that are linked to Application in that template?

          For example, under the Linux OS template I see CPU listed under Application with "Items (13)" across from it.

          Comment

          • BDiE8VNy
            Senior Member
            • Apr 2010
            • 680

            #6
            When no further action condition limits the events to consider, then Yes.
            The action would then consider events created by every trigger where one of these items is used in the expression.

            Comment

            • DreamMark
              Junior Member
              • Oct 2014
              • 8

              #7
              As far as passing custom parameters to my script. I'm I limited to:

              to=$1
              subject=$2
              body=$3

              ... as demonstrated in Zabbix's documentation?

              For example. If I want to pass {$CUSTOM_MACRO} to the script. I can see the parameter being passed when I add {$CUSTOM_MACRO} to the subject field in the action, and then use $subject in the script, but no other way.

              I suppose I cannot just use {$CUSTOM_MACRO} in the script itself?

              Comment

              • BDiE8VNy
                Senior Member
                • Apr 2010
                • 680

                #8
                Correct. Using macros within the script does not work since Zabbix just executes the script/program and passes the three parameters.

                Comment

                • DreamMark
                  Junior Member
                  • Oct 2014
                  • 8

                  #9
                  Got it working. Here's an example in case others want to see.

                  I created an action and filled the Subject ($2) and Body ($3) with some macros. The Body has one custom macro {$CPU_CODE} with the value SEA00100. I used comma as a delimiter.



                  Then I created the following script and put it in the alertscripts directory:

                  #!/bin/bash

                  IFS=',' read -a array <<< "$3"

                  echo CPU CODE: "${array[0]}" HOST NAME: "${array[1]}" ITEM NAME, VALUE, ETC.: "${array[2]}" > /usr/lib/zabbix/alertscripts/demo.txt

                  exit
                  The script inputs the values from the body ($3) to an array and then echoes those values to a file called demo.txt. I had the script fire for CPU load on a test server called JANUS.LOC.

                  Here's the output in demo.txt.

                  CPU CODE: SEA00100 HOST NAME: JANUS.LOC ITEM NAME, VALUE, ETC.: Processor load (1 min average per core) (JANUS.LOC:system.cpu.load[percpu,avg1]): 5.51
                  You can see how it pulled the values (highlighted in red) from the macros in the body.
                  Last edited by DreamMark; 16-12-2014, 21:25.

                  Comment

                  Working...