centreon / centreon-plugins

Collection of standard plugins to discover and gather cloud-to-edge metrics and status across your whole IT infrastructure.
https://www.centreon.com
Apache License 2.0
310 stars 273 forks source link

How can I add a new metric? #4996

Open wp-perc opened 4 months ago

wp-perc commented 4 months ago

Hello,

I noticed plugin apps::protocols::x509::plugin has no perfdata, while I think having the remaining expiration of a certificate as a metric can be a useful. Therefore, I tried to use --extend-perfdata to add variable expiration as a metric, but I am unable to do so, and I am also unable to find documentation about it. Can you help me in finding a way to add %{expiration} as a perfdata?

For reference, my command line:

/usr/lib/centreon/plugins/centreon_protocol_x509.pl --plugin apps::protocols::x509::plugin --mode certificate --custommode tcp --hostname X.Y.Z.K --port 9200 --warning-status '%{expiration} < 60' --critical-status '%{expiration} < 30 || %{subject} !~ /^EXPECTEDSUBJECT$/'
lucie-dubrunfaut commented 1 month ago

Hello :)

I'm not sure I understand exactly what you mean by converting certificate expiration in a metric? Would you like to apply thresholds etc on it? About the option --extend-perfdata I only find this help section :

Change or extend perfdata.
Syntax: --extend-perfdata=searchlabel,newlabel,target[,[newuom],[min],[max]]

I'm not sure how this option works or how it is supported, maybe you could show us an example output with this option (and with the --debug option)?

wp-perc commented 1 month ago

Hi, let me rephrase.

I would like to have the remaining certificate's validity days returned as performance data. It may be silly, but this allows me to make reports and more complex monitoring.

Here the debug output (I removed the check of subjects because it is a test server):

# /usr/lib/centreon/plugins/centreon_protocol_x509.pl --plugin apps::protocols::x509::plugin --mode certificate --custommode tcp --hostname X.Y.Z.K --port 9200 --warning-status '%{expiration} < 60' --critical-status '%{expiration} < 30' --debug
OK: Certificate for 'satellite.test' expires in '3586' days [2034-05-14T08:25:23Z] - Issuer: '/DC=local/DC=*/O=Test/OU=Root CA/CN=*.local'
Alternative subject names: satellite.local, X.Y.Z.K, 127.0.0.1.

I am trying to have the 3586 days in the perfdata. I tried with --extend-perfdata, but since the documentation about perfdata manipulation is lacking I had no luck. Maybe someone that has more insights than me can provide a solution...

lucie-dubrunfaut commented 1 month ago

Hello :)

Okay I understand your need, and based on my understanding I am not sure that the --extend-perfdata option can apply in this case because this mode returns a status and not a metric . It would be possible to add a second counter which is a metric and which displays the days remaining before the license expires, however this is a request for improvement of the plugin and these are done on TheWatch to be take into account and vote on (you can link this github issue in your idea proposition).