Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cloud::azure::management::monitor::plugin] - mode=(get-metrics): UNKNOWN: No metric found (Are the filters properly set?) #5205

Closed
gust102 opened this issue Sep 26, 2024 · 12 comments
Labels

Comments

@gust102
Copy link

gust102 commented Sep 26, 2024

Hi,

I have an issue with this command :

/usr/lib64/nagios/plugins/centreon_plugins.pl --plugin cloud::azure::management::monitor::plugin \
--custommode='api' \
--mode='get-metrics' \
--subscription=xxx \
--tenant=xxx \
--client-id=xxx \
--client-secret=xxx \
--resource=xxx \
--resource-group=xxx \
--resource-namespace=microsoft.insights/components \
--resource-type=  \
--metric=requests/failed \
--aggregation=Count \
--interval=PT30M \
--filter-dimension="request/resultCode sw '42'" \
--warning-metric=1 --critical-metric=5

When there are no hits, i get:
UNKNOWN: No metric found (Are the filters properly set?)

Can't find any option to get OK instead of UNKNOWN when the filter is empty.

BR
Fredrik

@lucie-dubrunfaut
Copy link
Contributor

lucie-dubrunfaut commented Oct 18, 2024

Hello :)

Have you tried the following generic options (which might do what you want):

--change-short-output --change-long-output :

Modify the short/long output that is returned by the plugin.
Syntax: --change-short-output=pattern~replacement~modifier
Most commonly used modifiers are i (case insensitive) and g (replace all occurrences).
Example: adding --change-short-output='OK~Up~gi' will replace all occurrences of 'OK', 'ok', 'Ok' or 'oK' with 'Up'

or

--output-ignore-labe :

Remove the status label ("OK:", "WARNING:", "UNKNOWN:", CRITICAL:") from the
beginning of the output.
Example: 'OK: Ram Total:...' will become 'Ram Total:...'

@gust102
Copy link
Author

gust102 commented Oct 21, 2024

Hello,

But that would only change the output text, and still the exit code will be 3 (UNKNOWN)?
What I am looking for is "as long as ResultCode not starts with 42, everything is OK (exit 0)"

BR
Fredrik

@lucie-dubrunfaut
Copy link
Contributor

Hello :)

Ok I need more context about your needs, but my first impression is that you may need an additional option to accept certain return codes. Can you provide us the plugin output with the option --debug set ? (you can anonymized part that need it)?

@gust102
Copy link
Author

gust102 commented Nov 5, 2024

/usr/lib64/nagios/plugins/centreon_plugins.pl --plugin cloud::azure::management::monitor::plugin \
                                              --custommode='api' \
                                              --mode='get-metrics' \
                                              --subscription=xxxx \
                                              --tenant=xxxx \
                                              --client-id=xxxx \
                                              --client-secret=xxxx \
                                              --resource=xxxx \
                                              --resource-group=xxxx \
                                              --resource-namespace=microsoft.insights/components \
                                              --resource-type=  \
                                              --metric=requests/failed \
                                              --aggregation=Count \
                                              --interval=PT30M \
                                              --filter-dimension="request/resultCode sw '42'" \
                                              --warning-metric=1 \
                                              --critical-metric=5 \
                                              --debug
UNKNOWN: No metric found (Are the filters properly set?)
== Info:   Trying 51.12.196.178:443...
== Info: Connected to management.azure.com (51.12.196.178) port 443 (#0)
== Info: ALPN, offering h2
== Info: ALPN, offering http/1.1
== Info:  CAfile: /etc/pki/tls/certs/ca-bundle.crt
== Info: TLSv1.0 (OUT), TLS header, Certificate Status (22):
== Info: TLSv1.3 (OUT), TLS handshake, Client hello (1):
== Info: TLSv1.2 (IN), TLS header, Certificate Status (22):
== Info: TLSv1.3 (IN), TLS handshake, Server hello (2):
== Info: TLSv1.2 (OUT), TLS header, Finished (20):
== Info: TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
== Info: TLSv1.2 (OUT), TLS header, Certificate Status (22):
== Info: TLSv1.3 (OUT), TLS handshake, Client hello (1):
== Info: TLSv1.2 (IN), TLS header, Finished (20):
== Info: TLSv1.2 (IN), TLS header, Certificate Status (22):
== Info: TLSv1.3 (IN), TLS handshake, Server hello (2):
== Info: TLSv1.2 (IN), TLS header, Unknown (23):
== Info: TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
== Info: TLSv1.3 (IN), TLS handshake, Certificate (11):
== Info: TLSv1.3 (IN), TLS handshake, CERT verify (15):
== Info: TLSv1.3 (IN), TLS handshake, Finished (20):
== Info: TLSv1.2 (OUT), TLS header, Unknown (23):
== Info: TLSv1.3 (OUT), TLS handshake, Finished (20):
== Info: SSL connection using TLSv1.3 / TLS_AES_256_GCM_SHA384
== Info: ALPN, server accepted to use h2
== Info: Server certificate:
== Info:  subject: C=US; ST=WA; L=Redmond; O=Microsoft Corporation; CN=management.azure.com
== Info:  start date: Oct  3 08:46:26 2024 GMT
== Info:  expire date: Apr  1 08:46:26 2025 GMT
== Info:  subjectAltName: host "management.azure.com" matched cert's "management.azure.com"
== Info:  issuer: C=US; O=Microsoft Corporation; CN=Microsoft Azure RSA TLS Issuing CA 04
== Info:  SSL certificate verify ok.
== Info: Using HTTP2, server supports multi-use
== Info: Connection state changed (HTTP/2 confirmed)
== Info: Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
== Info: TLSv1.2 (OUT), TLS header, Unknown (23):
== Info: TLSv1.2 (OUT), TLS header, Unknown (23):
== Info: TLSv1.2 (OUT), TLS header, Unknown (23):
== Info: Using Stream ID: 1 (easy handle 0x559288c1e650)
== Info: TLSv1.2 (OUT), TLS header, Unknown (23):
=> Send header: GET /subscriptions/xxxx/resourceGroups/xxxx/providers/microsoft.insights/components//xxxx/providers/microsoft.insights/metrics?api-version=2018-01-01&metricnames=requests%2Ffailed&aggregation=Count&timespan=2024-11-05T14%3A36%3A21Z%2F2024-11-05T14%3A46%3A21Z&interval=PT30M&$filter=request/resultCode%20sw%20'42' HTTP/2
Host: management.azure.com
accept:application/json
authorization:Bearer xxxxx

== Info: TLSv1.2 (IN), TLS header, Unknown (23):
== Info: TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
== Info: TLSv1.2 (IN), TLS header, Unknown (23):
== Info: TLSv1.2 (OUT), TLS header, Unknown (23):
== Info: TLSv1.2 (IN), TLS header, Unknown (23):
== Info: TLSv1.2 (IN), TLS header, Unknown (23):
=> Recv header: HTTP/2 200
=> Recv header: cache-control: no-cache
=> Recv header: pragma: no-cache
=> Recv header: content-length: 698
=> Recv header: content-type: application/json; charset=utf-8
=> Recv header: expires: -1
=> Recv header: x-ms-correlation-request-id: xxxx
=> Recv header: x-ms-ratelimit-remaining-subscription-resource-requests: 999
=> Recv header: request-context: appId=cid-v1:xxxx
=> Recv header: x-ms-request-id: xxxx
=> Recv header: strict-transport-security: max-age=31536000; includeSubDomains
=> Recv header: x-ms-routing-request-id: SWEDENSOUTH:20241105T144536Z:xxxx
=> Recv header: x-content-type-options: nosniff
=> Recv header: date: Tue, 05 Nov 2024 14:45:36 GMT
=> Recv header:
=> Recv data: {"cost":9,"timespan":"2024-11-05T14:36:21Z/2024-11-05T14:46:21Z","interval":"PT30M","value":[{"id":"/subscriptions/xxxx/resourceGroups/xxx/providers/microsoft.insights/components/xxx/providers/Microsoft.Insights/metrics/requests/failed","type":"Microsoft.Insights/metrics","name":{"value":"requests/failed","localizedValue":"Failed requests"},"displayDescription":"Count of HTTP requests marked as failed. In most cases these are requests with a response code >= 400 and not equal to 401.","unit":"Count","timeseries":[],"errorCode":"Success"}],"namespace":"microsoft.insights/components","resourceregion":"westeurope"}
== Info: TLSv1.2 (IN), TLS header, Unknown (23):
== Info: Connection #0 to host management.azure.com left intact


@lucie-dubrunfaut lucie-dubrunfaut changed the title UNKNOWN: No metric found (Are the filters properly set?) cloud::azure::management::monitor::plugin - mode='get-metrics : UNKNOWN: No metric found (Are the filters properly set?) Nov 7, 2024
@lucie-dubrunfaut lucie-dubrunfaut changed the title cloud::azure::management::monitor::plugin - mode='get-metrics : UNKNOWN: No metric found (Are the filters properly set?) cloud::azure::management::monitor::plugin - mode=(get-metrics): UNKNOWN: No metric found (Are the filters properly set?) Dec 12, 2024
@lucie-dubrunfaut lucie-dubrunfaut changed the title cloud::azure::management::monitor::plugin - mode=(get-metrics): UNKNOWN: No metric found (Are the filters properly set?) [cloud::azure::management::monitor::plugin] - mode=(get-metrics): UNKNOWN: No metric found (Are the filters properly set?) Dec 12, 2024
@lucie-dubrunfaut
Copy link
Contributor

Hello :)

Sorry for waiting, there is a PR that could solve your problem. Would you be able to test it to see if it solves your problem? Here is the new option:

<--change-output-adv>
Replace short output and exit code based on a "if" condition using the following variables:
short_output, exit_code.
Variables must be written either %{variable} or %(variable).
Example: adding --change-output-adv='%(short_ouput) =~ /UNKNOWN: No daemon/,OK: No daemon,OK' will 
change the following specific UNKNOWN result to an OK result.

#5155

@gust102
Copy link
Author

gust102 commented Dec 18, 2024

How do I use this PR?
Because, when I use this option in current installation I get error:
Unknown option: change-output-adv at /usr/lib64/nagios/plugins/centreon/plugins/alternative/Getopt.pm line 81.

@lucie-dubrunfaut
Copy link
Contributor

Hello :)

It's normal not to be able to use the option in the current develop branch of centreon-plugins. You need to be familiar with git branches and their use to be able to use the PR as it is currently proposed. If this is not the case, the option should be available soon in the January 2025 release.

@gust102
Copy link
Author

gust102 commented Dec 19, 2024

Ok, I have now tried with this pull request, by updating output.pm.
The parameter --change-output-adv is working, but I will still get exit code 3 (UNKNOWN).
image
I want exit code 0 (green).
BR
Fredrik

@lucie-dubrunfaut
Copy link
Contributor

Hello :)

OK, I understand, but it's more complicated because this mode is designed with the philosophy that ‘No metrics’ is not good news given that we're trying to recover metrics. So changing the return code from 3 (UNKNOWN) to 0 (OK) seems to require a change in approach to what the mode proposes to do. So it would be more of an enhancement request to incorporate the behaviour you want rather than an issue itself. Enhancement requests are processed in the TheWatch Ideas section for voting (which helps us prioritise them).

@omercier
Copy link
Contributor

Hi @gust102,
Can you show us the argument you have tried with option --change-output-adv?

@omercier
Copy link
Contributor

omercier commented Jan 7, 2025

Hi @gust102,
Can you try again with the code available here #5379 ?

@lucie-dubrunfaut
Copy link
Contributor

Hello :)

Released in January 2025
I close this issue because this option should meet your needs. If not feel free to re-open it. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants