Giter Site home page Giter Site logo

output formatting guide about nagiosplugin HOT 1 OPEN

mpounsett avatar mpounsett commented on July 28, 2024
output formatting guide

from nagiosplugin.

Comments (1)

mpounsett avatar mpounsett commented on July 28, 2024

Original comment by Christian Kauhaus (Bitbucket: ckauhaus, GitHub: ckauhaus).


Quan Tong Anh:

How to show different fmt_metric based on the value?

I'm writing a Nagios plugin that use xml output from sslyze to calculate SSL score based on Qualys Server Rating Guide.

Here're my code:

#!python
                if certificateMatchesServerHostname == 'True' and expire_in.days > 0 and validationResult == 'ok':
                    ...
                    final_score = protocol_score * 0.3 + key_score * 0.3 + cipher_score * 0.4
                    return [nap.Metric('sslscore', final_score, min=0, max=100)]
                elif certificateMatchesServerHostname != 'True':
                    return [nap.Metric('serverHostname', hostnameValidation[0].attrib['serverHostname'])]
                elif expire_in.days <= 0:
                    return [nap.Metric('expireInDays', expire_in.days)]
                elif validationResult != 'ok':
                    return [nap.Metric('validationResult', validationResult)]

    @nap.guarded
    def main():
        check = nap.Check(
            SslConfiguration(),
            nap.ScalarContext('sslscore', nap.Range('@65:80'), nap.Range('@0:65')),
            nap.ScalarContext('serverHostname', fmt_metric='The certificate does not match the host name {value}'),
            nap.ScalarContext('expireInDays', nap.Range('@:0'), fmt_metric='The certificate expired {value} days ago'),
            nap.ScalarContext('validationResult', fmt_metric='This server\'s certificate is not trusted: {value}'))
        check.main(timeout=60)

The reason I have to use multiple ScalarContext is I would like to show different fmt_metric if there is a problem with SSL certificate: does not match, expired, not trust, ...

With the above code, the output looks something like this:

SSLCONFIGURATION CRITICAL - The certificate does not match the host name a.b.c.d (outside range 0:)
critical: The certificate does not match the host name a.b.c.d (outside range 0:)
| serverHostname=a.b.c.d

What I really want to display is:

SSLCONFIGURATION CRITICAL - final_score is 0 (The certificate does not match the host name a.b.c.d) | sslscore=0;@65:80;@65;0;100

So, I have some questions:

  1. How can I display different fmt_metric based on the sslscore value, in only one context sslscore?

  2. How to remove the redundant line (2nd)?

    critical: The certificate does not match the host name a.b.c.d (outside range 0:)

  3. How to move the metric (3rd line) to at the end of the first line?

from nagiosplugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.