Ad Widget

Collapse

Regular Expressions and Discovery

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ElVengador
    Junior Member
    • Apr 2021
    • 29

    #1

    Regular Expressions and Discovery

    Hey guys,

    I have done so many searcing for a solution, but there is nothing which is solving my problem.

    I have set following Regular Expressions:
    Code:
    ^(MMCSS|gupdate|SysmonLog|clr_optimization_v2.0.50 727_32|clr_optimization_v4.0.30319_32|WbioSrvc|GIS vc|OneSyncSvc_.*|BITS|^.*TrustedInstaller.*|VeeamV ssSupport|PRTGProbeService|WpnUserService_.*|CDPUs erSvc_.*)$
    [Result is FALSE]
    When a new Windows server is automatically added to Zabbix and the Template "Windows by Zabbix agent" is added, all services are discovered. Also the services which are excluded via regular expression.

    Click image for larger version  Name:	Screenshot 2021-04-01 113303.png Views:	5 Size:	13.5 KB ID:	421913

    I'm using Zabbix 5.2 from ISO and it has been installed yesterday.
    What I'm doing wrong?

    Thank you!


    Best regards, Michael
    Last edited by ElVengador; 01-04-2021, 12:15.
  • mwildam
    Member
    • Feb 2021
    • 72

    #2
    Where exactly did you put that regular expression? - On the discovery rule there is a tab "Filters" - you should put your expression there (assuming it is correct - did only a fast check for obvious errors).

    Comment

    • ElVengador
      Junior Member
      • Apr 2021
      • 29

      #3
      Originally posted by mwildam
      Where exactly did you put that regular expression? - On the discovery rule there is a tab "Filters" - you should put your expression there (assuming it is correct - did only a fast check for obvious errors).
      I put it within th administrative section in zabbix like it's described in the documentation:
      Click image for larger version  Name:	Screenshot 2021-04-01 164121.png Views:	0 Size:	53.8 KB ID:	421940

      Comment

      • mwildam
        Member
        • Feb 2021
        • 72

        #4
        Did you try your regex with a few of your service names on https://regex101.com/ for example?
        And I would give it a try using that expression in the filters.

        Comment

        • ElVengador
          Junior Member
          • Apr 2021
          • 29

          #5
          Originally posted by mwildam
          Did you try your regex with a few of your service names on https://regex101.com/ for example?
          And I would give it a try using that expression in the filters.
          Click image for larger version

Name:	Screenshot 2021-04-02 081139.png
Views:	5662
Size:	69.9 KB
ID:	422038
          Why should I use a filter in the template? What if there are changes on the template and the filter isn't available anymore or the entries are gone?
          Why is there a central option when it's not working? Maybe I'm using it wrong?!

          Best regards, Michael

          Comment

          • ElVengador
            Junior Member
            • Apr 2021
            • 29

            #6
            Do we have any solution? I find so many threads about regular expressions and that they don't work.

            Comment

            • mwildam
              Member
              • Feb 2021
              • 72

              #7
              In general, regular expressions are not the easiest thing. Milking a cow is far easier, even for an IT tech. ;-) - Apart from that I think, that you have to consider, that it also depends on the underlying data where the regular expression is applied to. In Zabbix you cannot debug this very well (or I just didn't discover yet how to do it).

              Regarding the filter: You use the filter, if you have a discovery rule that finds more stuff that you actually want to monitor. Of course you could also change your discovery rule script to not report stuff you don't want. The filter is an option to exclude reported stuff, you don't want to monitor. The discovery report part could also be a binary which you cannot change, so this option makes sense. Of course it is more efficient, if you can omit reporting stuff you don't need in the first place.

              Comment

              • ElVengador
                Junior Member
                • Apr 2021
                • 29

                #8
                Originally posted by cyber
                If you use templates from 5.2 also, then those have "local" filter in template, as mentioned above. Those global regexes do not apply there. They are there only for backward compatibility (if you upgrade from earlier versions, your templates are not replaced and have to keep working).
                So I always have to edit the template because I am using 5.2 (fresh installation)? Are there any limitations? For example the length of the entry in the macro of the template?
                Last edited by ElVengador; 06-04-2021, 10:21.

                Comment

                • mwildam
                  Member
                  • Feb 2021
                  • 72

                  #9
                  If you use a fresh installation but using an existing database or importing templates or other configuration data, yes, you need to edit and adopt, if the database or data have been used with a different version before.

                  Comment

                  • mwildam
                    Member
                    • Feb 2021
                    • 72

                    #10
                    And BTW: I noticed, that with your expression you want to handle exceptions - so I assume you are also missing the "!" in your expression to tell it, reported entities should NOT match any of the given service names.

                    Comment

                    • ElVengador
                      Junior Member
                      • Apr 2021
                      • 29

                      #11
                      Originally posted by mwildam
                      If you use a fresh installation but using an existing database or importing templates or other configuration data, yes, you need to edit and adopt, if the database or data have been used with a different version before.
                      As I wrotebefore, it's a completely fresh installation. No existing database or anything else. Do I also have to make the exclusions in the template?

                      Originally posted by mwildam
                      And BTW: I noticed, that with your expression you want to handle exceptions - so I assume you are also missing the "!" in your expression to tell it, reported entities should NOT match any of the given service names.
                      I can't follow you in this case? Where am I missing the "!"?
                      I'm really confused now... Can we make a short break and you tell me what I have to do?

                      1) Fresh installation
                      2) Edit global exclusions? yes/no
                      3) Edit Template? yes/now
                      4) Which regex do I have to use?

                      I'm not an expert in regex. I'm only trying to figure out how it works when I compare different solutions I find on the internet. :-(

                      Comment

                      • mwildam
                        Member
                        • Feb 2021
                        • 72

                        #12
                        Originally posted by ElVengador
                        Do I also have to make the exclusions in the template?
                        In general your global expressions are used by the templates - or even not. I have in my (also pretty recent fresh installation) 2 different Windows templates that are service related. I don't use them as I don't have any single Windows Server in my environment, but I took a look at them: And I don't find a reference to the global expressions there. They only refer to template or host macros (macros from templates are inherited to hosts but can be overwritten there). I am not sure because also pretty new to zabbix, but maybe these (default) expressions are there only for backward compatibility. But in your case might be different or you might have changed your configuration or imported some external template. From your last comment, I assume, you are using everything in default and added one of the two "Windows Services ..." templates to your host(s). And in that case I think, those expressions are not used anyway.

                        Originally posted by ElVengador
                        I can't follow you in this case? Where am I missing the "!"?
                        I'm really confused now... Can we make a short break and you tell me what I have to do?
                        Sorry for that - I did not see, you changed the "Result" to false for that expression. - The "!" is a NOT in regular expression writing - see https://stackoverflow.com/questions/...ch-with-regexp

                        Originally posted by ElVengador
                        2) Edit global exclusions? yes/no
                        3) Edit Template? yes/now
                        4) Which regex do I have to use?
                        After looking at the default windows related templates, I think, those global expressions are not used in the current templates. In general: You can define global expressions and macros (maybe misleading name - macros are basically variables). So not only expressions can be defined globally - also Macros:
                        Click image for larger version

Name:	Global-Macros.png
Views:	5764
Size:	60.0 KB
ID:	422376

                        Macros can be defined also on template and host level and are inherited from template to hosts (and can be overwritten there - as mentioned above).

                        BUT: All those are irrelevant if not used!

                        In my 5.2.4 version I can see the following filters in the discovery rules for windows services:
                        Click image for larger version

Name:	Service-Discovery-Rule.png
Views:	5787
Size:	86.9 KB
ID:	422377

                        Those refer to MACROS! - You can see this by the "{}" enclosed expressions and the # or $ sign (built-in vs user defined macros). So you need to look at the template level macros or host macros:
                        Click image for larger version

Name:	Windows-Template-Macros.png
Views:	5788
Size:	135.2 KB
ID:	422378

                        If you want to refer to your global expressions you would have to use @ - like this:
                        Click image for larger version

Name:	Reference2globalexpression.png
Views:	5739
Size:	44.3 KB
ID:	422379

                        So to sum up: From current knowledge, I think you can put your favorite quote there into the global expression and it would not make any difference because not referenced by the actual templates.
                        I am sorry for creating confusion. I did not look at the actual templates and assumed, that those expressions are used in the templates / in your configuration.

                        Originally posted by ElVengador
                        I'm not an expert in regex. I'm only trying to figure out how it works when I compare different solutions I find on the internet. :-(
                        I am pretty sure, that there are not soo many real experts in regular expressions out there. I do not consider myself as one of them either. :-(

                        Comment

                        • ElVengador
                          Junior Member
                          • Apr 2021
                          • 29

                          #13
                          Originally posted by mwildam
                          In general your global expressions are used by the templates - or even not. I have in my (also pretty recent fresh installation) 2 different Windows templates that are service related. I don't use them as I don't have any single Windows Server in my environment, but I took a look at them: And I don't find a reference to the global expressions there. They only refer to template or host macros (macros from templates are inherited to hosts but can be overwritten there). I am not sure because also pretty new to zabbix, but maybe these (default) expressions are there only for backward compatibility. But in your case might be different or you might have changed your configuration or imported some external template. From your last comment, I assume, you are using everything in default and added one of the two "Windows Services ..." templates to your host(s). And in that case I think, those expressions are not used anyway.


                          Sorry for that - I did not see, you changed the "Result" to false for that expression. - The "!" is a NOT in regular expression writing - see https://stackoverflow.com/questions/...ch-with-regexp


                          After looking at the default windows related templates, I think, those global expressions are not used in the current templates. In general: You can define global expressions and macros (maybe misleading name - macros are basically variables). So not only expressions can be defined globally - also Macros:
                          Click image for larger version

Name:	Global-Macros.png
Views:	5764
Size:	60.0 KB
ID:	422376

                          Macros can be defined also on template and host level and are inherited from template to hosts (and can be overwritten there - as mentioned above).

                          BUT: All those are irrelevant if not used!

                          In my 5.2.4 version I can see the following filters in the discovery rules for windows services:
                          Click image for larger version

Name:	Service-Discovery-Rule.png
Views:	5787
Size:	86.9 KB
ID:	422377

                          Those refer to MACROS! - You can see this by the "{}" enclosed expressions and the # or $ sign (built-in vs user defined macros). So you need to look at the template level macros or host macros:
                          Click image for larger version

Name:	Windows-Template-Macros.png
Views:	5788
Size:	135.2 KB
ID:	422378

                          If you want to refer to your global expressions you would have to use @ - like this:
                          Click image for larger version

Name:	Reference2globalexpression.png
Views:	5739
Size:	44.3 KB
ID:	422379

                          So to sum up: From current knowledge, I think you can put your favorite quote there into the global expression and it would not make any difference because not referenced by the actual templates.
                          I am sorry for creating confusion. I did not look at the actual templates and assumed, that those expressions are used in the templates / in your configuration.


                          I am pretty sure, that there are not soo many real experts in regular expressions out there. I do not consider myself as one of them either. :-(
                          Thank you very much. Now I'm on the right way :-)

                          Comment

                          • ElVengador
                            Junior Member
                            • Apr 2021
                            • 29

                            #14
                            Originally posted by cyber

                            Yes. you should modify your template (or clone it and modify that one, if you want to keep original available). Do not worry, if any future update/upgrade has new versions of templates, they will not overwrite your changes. Update of templates is left for you to do then, so you can include those changes, what you need.

                            Macro length is stated in docs
                            "Maximum length of a user macro value is 2048 characters (255 characters in versions before 5.2.0)."

                            If this is too short for you, you can always use JS preprocessing and drop info directly from discovery json. There you are not limited to any length.
                            OK, thank you. Now I understand it better. Do yout have any links for reasearch how to use json preprocessing?

                            Comment

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

                              #15
                              If you use templates from 5.2 also, then those have "local" filter in template, as mentioned above. Those global regexes do not apply there. They are there only for backward compatibility (if you upgrade from earlier versions, your templates are not replaced and have to keep working).

                              Comment

                              Working...