Ad Widget

Collapse

External Script Complex Output?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • js1
    Member
    • Apr 2009
    • 66

    #1

    External Script Complex Output?

    Can Zabbix process complex output from an external script? For example, if I want to monitor the performance of my DNS server with a custom script that uses dig and returns the DNS answer as well as the query time. How can I have zabbix process the output so that the DNS response can be used in a trigger expression and the query time can be graphed?

    Or, do I need to create two external checks, one for the DNS response and another for the query time?
  • nelsonab
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • Sep 2006
    • 1233

    #2
    Yes... and No... and perhaps...

    Not quite the answer you wanted?

    Here are two ways to go about doing this.

    Method 1, simpler in the short run but this is not my favored approach

    Write your script to parse DNS and then use the Zabbix Sender to send the results back into Zabbix. Cron is the likely choice for firing off the job.

    Disadvantages, if you change the key you store the value under you need to update the script. If cron fails, you're hosed. If cron does not fire off the job often enough you'll get some trigger flap.

    Method 2, harder in the short run but better overall

    This is done as a custom UserParameter in the Zabbix Agent.

    You'll need to write a wrapper to your main script first. The wrapper will poll a data file and determine it's age. If the file is within the appropriate age range (this can be a parameter passed by the zabbix server if you program it right) it will then just read the data file and spit back the result.

    If the file is outside the appropriate age range it will fire off the main script which will then put it's data into the data file queried before. The wrapper then reads the new data file and returns the result. Your data file can have a simple format of:
    item1 1234
    item2 bla bla bla
    item3 5678

    Your wrapper does a grep for the item in question, and then passes that to "cut" or awk to cut out the item name and returns the results.

    Disadvantage: kinda tricky to write initially
    Advantage: The Zabbix server is in charge of the timing. Also if your script is time or cpu intensive and results in many data points the data points get stored and the script is run only when necisary. We used this method at a former client site and had excellent results and found race conditions were not an issue (i could go into it but it has to do with how unix does file handles).

    So how would you call this?

    first setup a user parameter
    UserParameter=dns.latency,dns_wrapper $1 latency
    UserParameter=dns.check,dns_wrapper $1 success

    You would then use the following keys
    dns.latency[1]
    dns.check[1]

    The parameter would denote the maximum allowed file age in minutes.

    Hopefully this helps with what you're trying to do.
    RHCE, author of zbxapi
    Ansible, the missing piece (Zabconf 2017): https://www.youtube.com/watch?v=R5T9NidjjDE
    Zabbix and SNMP on Linux (Zabconf 2015): https://www.youtube.com/watch?v=98PEHpLFVHM

    Comment

    Working...