NagiosEnterprises / nrpe

NRPE Agent
GNU General Public License v2.0
257 stars 133 forks source link

Feature Request - Support wildcards in exclude arguments #282

Open ne-lgute opened 6 months ago

ne-lgute commented 6 months ago

When services need to be excluded, and the service name includes things like version numbers, the exclude argument needs to be changed every time the version number is updated.

Add support for wild cards and/or head/tail type matching rules, so the exclude argument does not need to be changed.

define command {
    command_name check_some_services
    command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -c CheckServiceState -a CheckAlc 
    exclude=XYZService122.0.6253.9 exclude=$ARG1$ exclude=$ARG2$ exclude=$ARG3$ exclude=$ARG4$ exclude=$ARG5$
}
smithmich commented 6 months ago

Can the number part of this service somehow be matched with regex? I can't figure it out. GoogleUpdaterInternalService124.0.6315.0

smithmich commented 6 months ago

This does not work in Nagios but it does match in regex calculator tests so maybe NRPE doesn't allow this regex expression. GoogleUpdaterService[0-9]{1,3}.[0-9]{1,2}.[0-9]{1,4}.[0-9]{1,2} or ^GoogleUpdaterService[0-9]{1,3}.[0-9]{1,2}.[0-9]{1,4}.[0-9]{1,2}$

bunste commented 5 months ago

Did you try to use the filter argument?

filter=(name not regexp str(GoogleUpdater.*))

smithmich commented 5 months ago

Yes. It doesn’t work with * Not really sure where I would put the filter part though.

Get Outlook for iOShttps://aka.ms/o0ukef


From: Stefan Bungter @.> Sent: Monday, February 26, 2024 2:54:44 AM To: NagiosEnterprises/nrpe @.> Cc: Smith, Michael @.>; Manual @.> Subject: Re: [NagiosEnterprises/nrpe] Feature Request - Support wildcards in exclude arguments (Issue #282)

Did you try to use the filter argument?

filter=(name not regexp str(GoogleUpdater.*))

— Reply to this email directly, view it on GitHubhttps://urldefense.com/v3/__https://github.com/NagiosEnterprises/nrpe/issues/282*issuecomment-1963606577__;Iw!!BCR0FSePrR4x!DZAYt0qfCJn0Ie-hyN2ZuVE5OnVdwzIg7Y64HKhyYFULlrKdRwaq4GERDaajOxAH8SR4NjVdKsQgHFTw0pGCs2Aqbg$, or unsubscribehttps://urldefense.com/v3/__https://github.com/notifications/unsubscribe-auth/AH5CQDG6SA7A2EJS6WFIHA3YVREVJAVCNFSM6AAAAABCXFHA62VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNRTGYYDMNJXG4__;!!BCR0FSePrR4x!DZAYt0qfCJn0Ie-hyN2ZuVE5OnVdwzIg7Y64HKhyYFULlrKdRwaq4GERDaajOxAH8SR4NjVdKsQgHFTw0pEOSD-I7Q$. You are receiving this because you are subscribed to this thread.Message ID: @.***>

bunste commented 5 months ago

Here is what what works for me. To exclude a service by name:

./check_nrpe -H IP_ADDRESS -c check_service -a 'exclude=gupdate'

Lets say the output (CRITICAL) lists both GoogleUpdaterInternalService124.0.6315.0 and GoogleUpdaterService124.0.6315.0

Then I can get rid off those two services with the following regex:

./check_nrpe -H IP_ADDRESS -c check_service -a 'exclude=gupdate!filter=(name not regexp str(GoogleUpdater.*))'

Using NRPE Plugin for Nagios version: 4.0.3

smithmich commented 5 months ago

OK I'm getting this error now running Nagios core 4.5.0 Failed to open service filter: 424: The specified service does not exist as an installed service. Here is my check command: It's in test environment but mirrors production with many exclusions.. define command{ command_name check_some_services command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -c CheckServiceState -a CheckAll exclude=RemoteRegistry exclude=wuauserv exclude=sppsvc exclude=gpsvc exclude=TrustedInstaller exclude=MapsBroker exclude=gupdate exclude=WbioSrvc exclude=CDPSvc exclude=tiledatamodelsvc exclude=BITS exclude=mfemms exclude=mfevtp exclude=ccmsetup exclude=edgeupdate exclude=WinDefend exclude=vm3dservice 'exclude=gupdate!filter=(name not regexp str(GoogleUpdater.*))' exclude=$ARG1$ exclude=$ARG2$ exclude=$ARG3$ exclude=$ARG4$ exclude=$ARG5$ }

smithmich commented 5 months ago

Update working. I was using the legacy CheckServiceStatus. I switched to the Check_Service and was able to filter the Google services like this: command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 60 -c Check_Service -a "filter=name not like 'Google'" exclude=RemoteRegistry exclude=wuauserv exclude=sppsvc exclude=gpsvc exclude=TrustedInstaller exclude=MapsBroker exclude=gupdate exclude=WbioSrvc exclude=CDPSvc exclude=tiledatamodelsvc exclude=BITS exclude=mfemms exclude=mfevtp exclude=ccmsetup exclude=edgeupdate exclude=WinDefend exclude=vm3dservice exclude=$ARG1$ exclude=$ARG2$ exclude=$ARG3$ exclude=$ARG4$ exclude=$ARG5$ #

Reference: https://nsclient.org/docs/reference/windows/CheckSystem/#check_service_filter

bambaleon commented 5 months ago

Hello. Where should i put this filter? Can you provide short manual, please?

smithmich commented 5 months ago

This line is in the /usr/local/nagios/etc/objects/commands.cfg file. On the host I have this to call it: define service { use generic-service ; host_name HOSTNAME ; service_description AllAutomatic Services ; servicegroups Service ; check_command check_some_services!mfevtp!TrustedInstaller ; }