Ad Widget

Collapse

Set trigger for string value

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sasanaalem
    Junior Member
    • Sep 2023
    • 28

    #1

    Set trigger for string value

    Hi, define a user parameter by bash script like below:

    Code:
    cat event_log.sh
    #!/bin/bash
    
    SNMP_HOST="192.168.60.33"
    SNMP_COMMUNITY="xxxxxxxxxxxx"
    BASE_OID="iso.3.6.1.4.1.232.9.2.3.2.1.4"
    
    OUTPUT=$(snmpwalk -v 2c -c $SNMP_COMMUNITY $SNMP_HOST $BASE_OID | tail -n 1 | awk -F' = ' '{print $2}')
    echo $OUTPUT
    ​and add it to my zabbix.agentd.conf and I add it as an item to my host with these values:

    name :iLO Event Logs
    type: zabbix agent
    key: ilo.events
    type: text
    update interval: 10s​
    and I test it in zabbix and i get this value

    STRING: "Browser logout: System Administrator - 127.0.0.1(localhost)."
    but I dont now how can I set a triger on it to if change set an alert to me!
    I do some way with regular expersion but it doesnt help me and I get
    Invalid parameter "/1/expression": incorrect expression starting from...
  • Vermizz
    Member
    • Oct 2022
    • 33

    #2
    Hi,
    If you want the trigger to fire when the value changes to another value you can use:
    Code:
    last(/you_host/ilo.events,#1)<>last(/you_host/ilo.events,#2)

    Comment

    • Hamardaban
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • May 2019
      • 2713

      #3
      Of course, you know better how to get SNMP data, but why not just use the built-in capabilities of zabbix? SNMP agent (maybe SNMP walk[] item)​ a​nd Item value preprocessing ?

      Comment

      • sasanaalem
        Junior Member
        • Sep 2023
        • 28

        #4
        First you know I want to get server power status for HPe servers.I get iLO uptime, but I want to get server power status that the server is on or not or it has been reset.
        Now I almost there!I have follow this way
        I install zabbix agent on ubuntu machine and I wrote these scripts

        Code:
        cat ilo_status.sh
        #!/bin/bash
        
        IP="$1"
        COMMUNITY_STRING="miVHL42T8G"
        OID="iso.3.6.1.4.1.232.9.2.3.2.1.4"
        
        # Fetch SNMP logs
        logs=$(snmpwalk -v 2c -c "$COMMUNITY_STRING" "$IP" "$OID")
        
        echo "$logs" | grep -E 'Server power removed.|Server reset.' | tail -n 1 | awk -F'= STRING: ' '{print $2}'
        Code:
        cat ilo_discovery.sh
        #!/bin/bash
        
        IPS=("192.168.60.33")
        OUTPUT="{\"data\":["
        
        for IP in "${IPS[@]}"; do
        OUTPUT+="{\"{#ILOIP}\":\"$IP\"},"
        done
        
        # Remove the trailing comma
        OUTPUT="${OUTPUT%,}"
        
        OUTPUT+="]}"
        
        echo "$OUTPUT"​
        and I add these to zabbix.agentd.conf

        UserParameter=ilo.discovery,/etc/zabbix/scripts/ilo_discovery.sh
        UserParameter=ilo.status[*],/etc/zabbix/scripts/ilo_status.sh $1​
        and in zabbix frontend I write this Discovery Rule

        Code:
        Name: iLO Discovery
        Type: Zabbix Agent
        Key: ilo.discovery
        Update interval​: 10s
        and after that I make an Item Prototype with this values

        name: iLO status for {#ILOIP}
        type: Zabbix Agent
        key: ilo.status[{#ILOIP}]
        type information: Text
        Update Interval: 10s
        and at the end I wrote an Trigger Prototype

        Code:
        Name:iLO Event Log Trigger
        Expression: last(/ba-DC-SRV1/ilo.status[{#ILOIP}])="Server reset."
        Severity: High
        now I get these valuese for
        ba-DC-SRV1: iLO status for 192.168.60.33
        2023-09-30 14:01:54 "Server reset."
        2023-09-30 14:01:30 "Server reset."
        2023-09-30 14:00:51 "Server reset."
        2023-09-30 13:59:38 "Server reset."
        2023-09-30 13:58:40 "Server reset."
        2023-09-30 13:57:49 "Server reset."
        2023-09-30 13:57:10 "Server reset."
        2023-09-30 13:56:23 "Server reset."


        but It has not been a problem!Why?!Can you help me?!
        Last edited by sasanaalem; 30-09-2023, 12:35.

        Comment

        • dimir
          Zabbix developer
          • Apr 2011
          • 1080

          #5
          These do not suit your needs? https://www.zabbix.com/integrations/hpe

          Comment

          • sasanaalem
            Junior Member
            • Sep 2023
            • 28

            #6
            Originally posted by dimir
            These do not suit your needs? https://www.zabbix.com/integrations/hpe
            none of these templates dont get that server is power on or off!these just get iLO uptime!they are different!

            Comment

            • sasanaalem
              Junior Member
              • Sep 2023
              • 28

              #7
              Click image for larger version

Name:	poweron.png
Views:	748
Size:	5.5 KB
ID:	471414
              I want to check this on zabbix!

              Comment

              • dimir
                Zabbix developer
                • Apr 2011
                • 1080

                #8
                OK, got it. Do you receive the quoted value (Server reset. VS "Server reset.")?

                Comment

                • sasanaalem
                  Junior Member
                  • Sep 2023
                  • 28

                  #9
                  Originally posted by dimir
                  OK, got it. Do you receive the quoted value (Server reset. VS "Server reset.")?
                  I am looking at the latest value of the iLO event log, and if it is equal to 'Server Reset', my trigger should be activated and create a problem, as I shown above.Now it catch it but it doesnt make a problem.
                  Last edited by sasanaalem; 30-09-2023, 15:27.

                  Comment

                  • Vermizz
                    Member
                    • Oct 2022
                    • 33

                    #10
                    Hi,
                    You can try using the "find" function in trigger
                    Documentation: https://www.zabbix.com/documentation...ctions/history
                    find(/host/key,10m,"like","error") → find a value that contains 'error' within the last 10 minutes until now

                    In your case:
                    Code:
                    find(/ba-DC-SRV1/ilo.status[{#ILOIP}],10m,"like","Server reset.")

                    Comment

                    • sasanaalem
                      Junior Member
                      • Sep 2023
                      • 28

                      #11
                      Originally posted by Vermizz
                      Hi,
                      You can try using the "find" function in trigger
                      Documentation: https://www.zabbix.com/documentation...ctions/history
                      find(/host/key,10m,"like","error") → find a value that contains 'error' within the last 10 minutes until now

                      In your case:
                      Code:
                      find(/ba-DC-SRV1/ilo.status[{#ILOIP}],10m,"like","Server reset.")
                      I will try it!

                      Comment

                      Working...