Ad Widget

Collapse

SSH Checks - Trim down the output

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • LukeAB93UK
    Member
    Zabbix Certified Specialist
    • Jun 2023
    • 72

    #1

    SSH Checks - Trim down the output

    Hello,

    So I am now trying to implement SSH checks for the Juniper Routers we deploy.

    I have been able to succesffuly SSH to the device and run the command I want that shows the output I just now need to filter the output to keep only the value I want.

    Click image for larger version

Name:	image.png
Views:	323
Size:	22.7 KB
ID:	465546

    As you can see I am getting an output but all I want to keep is that value underlined in blue and literally junk everything else.

    I did think of doing this by trimming the collums in my command that is being run by Zabbix on the Juniper however there is no rear trim to remove the stuff after the "79999" as well so if I trimmed the collums I would only be able to get rid of where it says Bit rate.

    I have tried using Javascript to do it

    parseNum = str => +str.replace(/[^.\d]/g, '');
    let str = 'a1b2c.d3e';
    console.log(parseNum(str));​

    but no dice I am always getting that output.

    So Can anyone guide me on how I can trim out all that extra stuff I dont need. I only want to keep the "79999".
  • Hamardaban
    Senior Member
    Zabbix Certified SpecialistZabbix Certified Professional
    • May 2019
    • 2713

    #2
    Why don't you just use the "Regular expression" type of preprocessing?


    Comment

    • LukeAB93UK
      Member
      Zabbix Certified Specialist
      • Jun 2023
      • 72

      #3
      Originally posted by Hamardaban
      Hey,

      I have had a look but I have never been very good at learning from the documentation, its helpfor for referencing but without an example of how I would do it laid out I struggle to get my head around it.

      I want to keep only the first number only that would be returned from that command being run via SSH

      Comment

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

        #4
        regex - "^Bit rate (kbps) :\s*(\d+)\s+.*$"
        output - \1

        Learn regular expressions and read the documentation.
        https://regex101.com/ - the best!

        Comment

        • LukeAB93UK
          Member
          Zabbix Certified Specialist
          • Jun 2023
          • 72

          #5
          Originally posted by Hamardaban
          regex - "^Bit rate (kbps) :\s*(\d+)\s+.*$"
          output - \1

          Learn regular expressions and read the documentation.
          https://regex101.com/ - the best!
          Hey There,

          I have tried but I am getting this error message

          Click image for larger version

Name:	image.png
Views:	295
Size:	7.1 KB
ID:	465580

          I would pull this infomration using SNMP but sadly there is no OID for the Downstream bitrate only the upstream

          Comment

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

            #6
            I think you copied it all... with ""-s ? leave ""-s out, it should match.

            Comment

            • LukeAB93UK
              Member
              Zabbix Certified Specialist
              • Jun 2023
              • 72

              #7
              Originally posted by cyber
              I think you copied it all... with ""-s ? leave ""-s out, it should match.
              Hey there,

              Click image for larger version

Name:	image.png
Views:	261
Size:	12.8 KB
ID:	465641

              This is how I have it set up. and its throwing this output
              • cannot perform regular expression "^Bit rate (kbps) :\s*(\d+)\s+.*$" match for value of type "string": pattern does not match

              Comment

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

                #8
                I think there is a little mistake.. ()-s should be escaped or they will be taken as capture group
                Try with "^Bit rate \(kbps\) :\s*(\d+)\s+.*$"

                Regular expression tester with syntax highlighting, explanation, cheat sheet for PHP/PCRE, Python, GO, JavaScript, Java, C#/.NET, Rust.

                Comment

                • LukeAB93UK
                  Member
                  Zabbix Certified Specialist
                  • Jun 2023
                  • 72

                  #9
                  Originally posted by cyber
                  I think there is a little mistake.. ()-s should be escaped or they will be taken as capture group
                  Try with "^Bit rate \(kbps\) :\s*(\d+)\s+.*$"

                  https://regex101.com/r/64AIfq/1
                  Hey,

                  Thanks for all the help so far but its still spitting out and I have never used regex before.
                  • cannot perform regular expression "^Bit rate \(kbps\) :\s*(\d+)\s+.*$" match for value of type "string": pattern does not match
                  Click image for larger version

Name:	image.png
Views:	270
Size:	11.1 KB
ID:	465660
                  Click image for larger version

Name:	image.png
Views:	266
Size:	18.3 KB
ID:	465661
                  This is how I have it set up.

                  Maybe I am missing something. I can monitor from OID strings and I've figured out custom alerting triggers and dashboards but I cant seem to get this to work. This is sort of a new job responsibility of mine and I have a Zabbix trainer coming here to train me in the next few months but in the mean time I am trying to do things on my own and.

                  Comment

                  Working...