Ad Widget

Collapse

Use Macro in bash script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Dominic.David
    Junior Member
    • Sep 2007
    • 8

    #1

    Use Macro in bash script

    Hello,

    is it possible to export the macro values to a bash script?

    For exemplar:
    I want export the {HOSTNAME} and {IPADDRESS} macro to a bash variable like $HOSTNAME and $IPADDRESS on the Zabbix Server. And then use it in a bash scrpt.

    Is it possible? If yes, how can I do that?

    Thank you.

    MfG
    Dominic
  • cstackpole
    Senior Member
    Zabbix Certified Specialist
    • Oct 2006
    • 225

    #2
    I am not sure if I understand what you are asking.

    If you are wanting the variables to work on an item check then take a look at the manual section 5.12.8

    If you are wanting the information passed to the script as an action then there are only 3 variables sent to it (that I am aware of anyway) Recipient, Subject and Message.

    If you can clarify what you are wanting to do, I will see what I can do to help.

    Have fun!

    Comment

    • Dominic.David
      Junior Member
      • Sep 2007
      • 8

      #3
      Hello,

      ok.

      I have 6 Servers. I do a Simple Check with icmpping.
      When a Server is going down I to run the following Script as a remote command on the Zabbix Server.
      Not on the Server with the error.

      I want to do a traceroute from the Zabbix Server to the Server with the error.

      Code:
      #!/bin/bash
      SUBJECT="Server Traceroute"
      EMAIL="[email protected]"
      EMAILMESSAGE="/home/zabbix/test.txt"
      tcptraceroute 192.168.xxx.xxx > /home/zabbix/test.txt
      
      /bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
      The Problem ist that I have to write these Script for each Server.

      What I'm looking for is a more flexible Script. Something like that:

      Code:
      #!/bin/bash
      HOSTNAME={HOSTNAME}
      IPADDRESS={IPADDRESS}
      
      SUBJECT="$HOSTNAME Traceroute"
      EMAIL="[email protected]"
      EMAILMESSAGE="/home/zabbix/test.txt"
      
      tcptraceroute $IPADDRESS > /home/zabbix/test.txt
      
      /bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
      You see i want to use the Zabbix Macros as a variable in a bash script.
      So I only need one Script for 6 Servers.

      You know what i mean?

      Thank you

      MfG
      Dominic
      Last edited by Dominic.David; 29-05-2008, 08:14.

      Comment

      • cstackpole
        Senior Member
        Zabbix Certified Specialist
        • Oct 2006
        • 225

        #4
        Sorry for the long delay; I was on vacation.

        I understand what you are asking for, but I do not think that is possible at this time. At least I was unable to find anything like that. You may want to put this as a suggestion on the 1.6 roadmap because I can see where something like that would be useful.

        Comment

        • Dominic.David
          Junior Member
          • Sep 2007
          • 8

          #5
          Hi,

          mh ok.
          Where I can finde the Roadmap?
          Or who can add it to the Roadmap?

          MfG
          Dominic

          Comment

          • cstackpole
            Senior Member
            Zabbix Certified Specialist
            • Oct 2006
            • 225

            #6
            Alexei reads all of the posts on the forum, however, he does not always respond. I am certain that he has read your request. Knowing this, I would still post elsewhere to catch the attention of other members of the community as they may have ideas to improve the feature.

            If you want to put up a quick posting and link back to this posting for the details you can add it to this discussion. That would be the perfect place for a quick blurb.

            If you want to rewrite your request and phrase it for exactly what you are wanting (eg more details on what exactly you want and why then what a quick post would allow) I would create a new post in the Suggestions and Feedback forum.

            Just make sure that you don't create a ton of the same posts as that is usually frowned upon But I personally would suggests a good post on the what and why and put it in the Suggestions and Feedback forum.

            Have fun and Good Luck!

            Comment

            • mpre
              Junior Member
              • Apr 2011
              • 7

              #7
              I know this is an old thread, but figured in case someone else is looking for the same ... here you go.

              I placed the following traceroute.sh script in /etc/zabbix/externalscripts/* on my monitoring server .. whichever one you want the traceroute to run from.

              Code:
              #!/bin/bash
              HOSTNAME=$1
              IPADDRESS=$2
              now=$(date +"%m_%d_%Y-%H:%M:%S")
              now2=$(date +"%H:%M:%S %m/%d/%Y")
              
              SUBJECT="Traceroute to $HOSTNAME @ $IPADDRESS $now2"
              EMAIL="[email protected]"
              EMAILMESSAGE="/tmp/tr-$HOSTNAME-$now.txt"
              
              traceroute -A $IPADDRESS > /tmp/tr-$HOSTNAME-$now.txt
              
              /bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE

              WEBUI: CONFIGURATION -> ACTIONS:
              Create your Action, within create an Action operation:
              Operation type: Remote command
              Remote command:
              1.8.x
              Code:
              MONITOR-SRV:/etc/zabbix/externalscripts/traceroute.sh "{HOSTNAME}" "{IPADDRESS}"
              2.x (IPADDRESS macro changes to HOST.IP)
              Code:
              MONITOR-SRV:/etc/zabbix/externalscripts/traceroute.sh "{HOSTNAME}" "{HOST.IP}"

              Comment

              Working...