Ad Widget

Collapse

Regular expression for obtain "text row"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SixArt
    Junior Member
    • Jul 2015
    • 22

    #1

    Regular expression for obtain "text row"

    Hi,

    I create a custom script that exec an ssh command and return a text like this:

    Code:
    <router>display nqa history test-instance monitor test
     NQA entry(monitor, test) history:
    Index T/H/P       Response Status       Address         Time               
     1    97849/1/15       2ms success      127.0.0.1     2019-08-13 11:44:51.461 DST
     2    97850/1/1        1ms success      127.0.0.1     2019-08-13 11:44:53.451 DST
     3    97850/1/2        2ms success      127.0.0.1     2019-08-13 11:44:55.461 DST
     4    97850/1/3        2ms success      127.0.0.1     2019-08-13 11:44:57.461 DST
     5    97850/1/4        2ms success      127.0.0.1     2019-08-13 11:44:59.471 DST
     6    97850/1/5        2ms success      127.0.0.1     2019-08-13 11:45:01.461 DST
     7    97850/1/6        2ms success      127.0.0.1     2019-08-13 11:45:03.381 DST
     8    97850/1/7        2ms success      127.0.0.1     2019-08-13 11:45:05.381 DST
     9    97850/1/8        2ms success      127.0.0.1     2019-08-13 11:45:07.381 DST
     10   97850/1/9        2ms busy      127.0.0.1     2019-08-13 11:45:09.381 DST
     11   97850/1/10       1ms success      127.0.0.1     2019-08-13 11:45:11.381 DST
     12   97850/1/11       2ms success      127.0.0.1     2019-08-13 11:45:13.391 DST
     13   97850/1/12       2ms success      127.0.0.1     2019-08-13 11:45:15.391 DST
     14   97850/1/13       1ms success      127.0.0.1     2019-08-13 11:45:17.401 DST
     15   97850/1/14       2ms success      127.0.0.1     2019-08-13 11:45:19.401 DST
     16   97850/1/15       2ms success      127.0.0.1     2019-08-13 11:45:21.401 DST
     17   97851/1/1        2ms success      127.0.0.1     2019-08-13 11:45:23.401 DST
     18   97851/1/2        2ms success      127.0.0.1     2019-08-13 11:45:25.411 DST
     19   97851/1/3        2ms success      127.0.0.1     2019-08-13 11:45:27.411 DST
     20   97851/1/4        2ms success      127.0.0.1     2019-08-13 11:45:29.411 DST
     21   97851/1/5        2ms success      127.0.0.1     2019-08-13 11:45:31.411 DST
     22   97851/1/6        1ms success      127.0.0.1     2019-08-13 11:45:33.451 DST
     23   97851/1/7        2ms success      127.0.0.1     2019-08-13 11:45:35.451 DST
     24   97851/1/8        2ms success      127.0.0.1     2019-08-13 11:45:37.451 DST
     25   97851/1/9        2ms success      127.0.0.1     2019-08-13 11:45:39.451 DST
     26   97851/1/10       2ms busy      127.0.0.1     2019-08-13 11:45:41.461 DST
     27   97851/1/11       1ms success      127.0.0.1     2019-08-13 11:45:43.391 DST
     28   97851/1/12       1ms success      127.0.0.1     2019-08-13 11:45:45.401 DST
     29   97851/1/13       2ms success      127.0.0.1     2019-08-13 11:45:47.411 DST
     30   97851/1/14       2ms success      127.0.0.1     2019-08-13 11:45:49.411 DST
     31   97851/1/15       2ms success      127.0.0.1     2019-08-13 11:45:51.411 DST
     32   97852/1/1        2ms success      127.0.0.1     2019-08-13 11:45:53.391 DST
     33   97852/1/2        2ms success      127.0.0.1     2019-08-13 11:45:55.391 DST
     34   97852/1/3        2ms success      127.0.0.1     2019-08-13 11:45:57.401 DST
     35   97852/1/4        2ms success      127.0.0.1     2019-08-13 11:45:59.391 DST
     36   97852/1/5        2ms success      127.0.0.1     2019-08-13 11:46:01.391 DST
     37   97852/1/6        1ms success      127.0.0.1     2019-08-13 11:46:03.401 DST
     38   97852/1/7        2ms success      127.0.0.1     2019-08-13 11:46:05.421 DST
     39   97852/1/8        1ms success      127.0.0.1     2019-08-13 11:46:07.421 DST
     40   97852/1/9        2ms success      127.0.0.1     2019-08-13 11:46:09.461 DST
     41   97852/1/10       2ms success      127.0.0.1     2019-08-13 11:46:11.461 DST
     42   97852/1/11       2ms success      127.0.0.1     2019-08-13 11:46:13.441 DST
     43   97852/1/12       2ms success      127.0.0.1     2019-08-13 11:46:15.481 DST
     44   97852/1/13       2ms success      127.0.0.1     2019-08-13 11:46:17.371 DST
     45   97852/1/14       2ms success      127.0.0.1     2019-08-13 11:46:19.371 DST
     46   97852/1/15       2ms success      127.0.0.1     2019-08-13 11:46:21.371 DST
     47   97853/1/1        1ms success      127.0.0.1     2019-08-13 11:46:23.461 DST
     48   97853/1/2        1ms success      127.0.0.1     2019-08-13 11:46:25.461 DST
     49   97853/1/3        2ms success      127.0.0.1     2019-08-13 11:46:27.441 DST
     50   97853/1/4        1ms success      127.0.0.1     2019-08-13 11:46:29.401 DST
    <router>
    Is possible, using prepocessor regular expression get only row with "busy" string like this??

    Code:
    10   97850/1/9        2ms busy      127.0.0.1     2019-08-13 11:45:09.381 DST
    26   97851/1/10       2ms busy      127.0.0.1     2019-08-13 11:45:41.461 DST
    how can i do this??

    Thanks in advance,

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

    #2
    try regex -
    template: ^ :*busy.*$
    output: \0
    Last edited by Hamardaban; 13-08-2019, 16:31.

    Comment

    • SixArt
      Junior Member
      • Jul 2015
      • 22

      #3
      Hi,

      like this???

      Click image for larger version

Name:	regularExpression.png
Views:	141
Size:	9.5 KB
ID:	384224

      Regards,

      Dario



      Attached Files

      Comment


      • Hamardaban
        Hamardaban commented
        Editing a comment
        Yes. pay attention to what is written exactly. there is no space between \ and 0. on the attached picture the wrong regex expression - must be ^.*busy.*$
    • SixArt
      Junior Member
      • Jul 2015
      • 22

      #4
      Hi,

      I insert ^.*busy.*$ in regular expression parameters an \0 in output, but this not work.

      I tested with text write in the first post but not work and I see this "error"

      Click image for larger version

Name:	regularExpression.png
Views:	135
Size:	11.1 KB
ID:	384245

      Regards,

      Dario
      Attached Files

      Comment


      • Hamardaban
        Hamardaban commented
        Editing a comment
        what type of data item do you use? text or string? what data does the item receive without using preproc?
    • SixArt
      Junior Member
      • Jul 2015
      • 22

      #5
      Hi,

      I exec python script and return a "str".

      The text without preprocessing is writed in the first post.


      Dario

      Comment

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

        #6
        Alter the script so that it make a set of lines, not a single line (insert line feed). And then regex will select the desired rows according to the template. And why not select the desired line immediately in the script??

        Comment

        • SixArt
          Junior Member
          • Jul 2015
          • 22

          #7
          I want do this with preprocessing because in first time I do this with script but I in the second time I want retrieve data with "ssh agent" item of zabbix.

          Dario

          Comment

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

            #8
            Do the data element with "ssh agent" and show what you will get in zabbix. Then we will continue.

            Comment

            Working...