Ad Widget

Collapse

Regex Assistance - or is there a better way?

Collapse
This topic has been answered.
X
X
 
  • Time
  • Show
Clear All
new posts
  • highway_fixer_man
    Member
    • Jun 2022
    • 35

    #1

    Regex Assistance - or is there a better way?

    Hi,


    I have a user parameter called "camera1.status" - it looks like this:

    Code:
    UserParameter=camara1.pingstatus,ping camara1 -c 1 -w 1 &>/dev/null; echo $?
    This returns 0 when the camera is online, and something else when its not. Well, at least the bash part does (ping camara1 -c 1 -w 1 &>/dev/null; echo $?)

    If I call this from Zabbix, I get the full output, even though I am piping the ping output to null:

    Code:
    0
    PING camara1 (10.10.102.21) 56(84) bytes of data.
    64 bytes from camara1 (10.10.102.21): icmp_req=1 ttl=64 time=0.240 ms
    
    --- camara1 ping statistics ---
    1 packets transmitted, 1 received, 0% packet loss, time 0ms
    rtt min/avg/max/mdev = 0.240/0.240/0.240/0.000 ms
    I am expecting to see only 0 or another number. I should not see the actual output of the command - not sure how this is finding its way through. Once I have the 0 or other number, I will use preprocessing to change it to "Camera is up" or "Camera is down" as needed.

    I am trying to figure out the regex I could use to match, but the fact that its multiline is really stumping me. I have tried several possibilities, and am using https://regex101.com/ to try and shape the regex. I can get it to match, but only line for line.

    Any advice?

  • Answer selected by highway_fixer_man at 24-05-2023, 13:11.
    highway_fixer_man
    Member
    • Jun 2022
    • 35

    I made a plan.

    I think I had an issue with my UserParameter.

    I changed it to:

    Code:
    ping camara1 -q -c 1 -w 1 2>&1 >/dev/null; result=$(echo $?); if ! [[ $result > 0 ]]; then echo "Camera is online"; else echo "Camera is offline"; fi​
    This gives me what I need. Dont even need to mess with preprocessing or value mapping. Yay! I will have to update 100 hosts, but that's my issue to deal with!

    Comment

    • cyber
      Senior Member
      Zabbix Certified SpecialistZabbix Certified Professional
      • Dec 2006
      • 4807

      #2
      Intreesting... I added same userparameter to my test host and depending on the configuration of the host what to ping there, it either returns 0 or 2.... in both ways, local testing (zabbix_agent2 -t) or zabbix_get from proxy...
      version is 6.0.16 and agent2 on linux...

      Instead of prerpocessing, you can use value mapping

      Comment

      • highway_fixer_man
        Member
        • Jun 2022
        • 35

        #3
        Originally posted by cyber
        Intreesting... I added same userparameter to my test host and depending on the configuration of the host what to ping there, it either returns 0 or 2.... in both ways, local testing (zabbix_agent2 -t) or zabbix_get from proxy...
        version is 6.0.16 and agent2 on linux...

        Instead of prerpocessing, you can use value mapping


        My version info:

        zabbix_server (Zabbix) 6.2.6
        Revision 6981d8b729a 5 December 2022, compilation time: Dec 5 2022 08:44:25

        I have a mix of agent and agent2 on about 100 hosts - they all do the same thing.

        I am glad to hear I am not going crazy - and that I SHOULD only get a 0 or 2 back. I would love to clean this up - but I have run out of ideas.

        Comment

        • highway_fixer_man
          Member
          • Jun 2022
          • 35

          #4
          I made a plan.

          I think I had an issue with my UserParameter.

          I changed it to:

          Code:
          ping camara1 -q -c 1 -w 1 2>&1 >/dev/null; result=$(echo $?); if ! [[ $result > 0 ]]; then echo "Camera is online"; else echo "Camera is offline"; fi​
          This gives me what I need. Dont even need to mess with preprocessing or value mapping. Yay! I will have to update 100 hosts, but that's my issue to deal with!

          Comment

          Working...