Ad Widget

Collapse

feeding discovery rule with item values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Plexus
    Junior Member
    • Feb 2014
    • 12

    #1

    feeding discovery rule with item values

    Hey there,

    we are working with AWS mainly and use burstable EC2 instances at some points. Burstable EC2 instances are virtual machines with CPU credits, which needs to be monitored, due giving an inoperable system if exhausted. We are obtaining this value with a cronjob-script from the AWS API sent to zabbix trapper and having a calculated item based on this trapper for the triggers. As not all instances are burstable those calculated items are extending my not supported items list unnecessary - so I would prefer establishing a discovery rule for this.

    I got a template with an item
    Code:
    system.run[curl -s -f http://169.254.169.254/latest/meta-data/instance-type]
    giving back t2.medium, t3.medium or t3a.medium for a medium sized, burstable instance for example.

    I created discovery rule being dependent on this item but as discovery rules can be fed with JSON only, I added a preprocessing step with JavaScript
    Code:
    return '{"data": {"name": "' + value + '"}}';
    This preprocessed JSON is passed to the LDD macro
    Code:
    {#INSTANCE_TYPE} pickup from JSONpath $.name
    and finally filtered by
    Code:
    {#INSTANCE_TYPE} matches ^t(2|3a?)\.(nano|micro|small|medium|large|xlarge|2xlarge)$
    Finally I added a prototype item dependent on the item mentioned at the beginning associating the appropiate maximum available CPU credits

    Click image for larger version

Name:	aws.png
Views:	555
Size:	35.1 KB
ID:	396936

    with JavaScript preprocessing
    Code:
    if (/^t2.nano$/.test(value)) {return 72};
    if (/^t(2\.micro|3a?\.nano)$/.test(value)) {return 144};
    if (/^t(2\.small|3a?\.micro)$/.test(value)) {return 288};
    if (/^t((2|3a?)\.medium|3a?\.small)$/.test(value)) {return 576};
    if (/^t(2|3a?).large$/.test(value)) {return 864};
    if (/^t2.xlarge$/.test(value)) {return 1296};
    if (/^t2.2xlarge$/.test(value)) {return 1958.4};
    if (/^t3a?.xlarge$/.test(value)) {return 2304};
    if (/^t3a?.2xlarge$/.test(value)) {return 4608};
    The discoery rule is reporting no errors although there is no item created.

    Please let me know how to proceed.

    Greetings,
    Plex
    Last edited by Plexus; 04-03-2020, 11:07.
  • Plexus
    Junior Member
    • Feb 2014
    • 12

    #2
    Ok I got it working after realizing that zabbix expects getting back a JSON list - even if filled with one element only.
    So the JS part looks like this:
    Code:
    return '[{"name": "' + value + '"}]'
    Thanks for your attention ... over and out!

    Comment

    Working...