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

output formatting guide #5

Open
mpounsett opened this issue Jan 14, 2015 · 1 comment
Open

output formatting guide #5

mpounsett opened this issue Jan 14, 2015 · 1 comment
Labels
documentation Improvements or additions to documentation needs review Needs developer review before assigning a milestone

Comments

@mpounsett
Copy link
Owner

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


show how to:

  • provide custom fmt_metric
  • subclass Context and override describe()
  • subclass Summary
@mpounsett
Copy link
Owner Author

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?

@mpounsett mpounsett added major documentation Improvements or additions to documentation feature New feature or request 2.0 needs review Needs developer review before assigning a milestone and removed 2.0 major labels Nov 7, 2019
@mpounsett mpounsett removed the feature New feature or request label Feb 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation needs review Needs developer review before assigning a milestone
Projects
None yet
Development

No branches or pull requests

1 participant