Comments (1)
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:
-
How can I display different
fmt_metric
based on the sslscore value, in only one contextsslscore
? -
How to remove the redundant line (2nd)?
critical: The certificate does not match the host name a.b.c.d (outside range 0:)
-
How to move the metric (3rd line) to at the end of the first line?
from nagiosplugin.
Related Issues (20)
- Control output of scientific number notation HOT 1
- Wrong argument order for (all ?) super(*,*) calls HOT 2
- Logged messages appear after the summary HOT 3
- Sample haproxy log, LICENSE, CONTRIBUTORS, etc not installed by package
- Move example code out of the nagiosplugin package into its own path
- Support of pytest capsys HOT 9
- nagiosplugin.state.Warn vs. nagiosplugin.state.Warning (considering nagiosplugin.state.Critical) HOT 1
- Support Nagios passive checks
- Default output only shows one failed metric HOT 4
- Best practice for "missing" metrics? HOT 3
- Support for extra-opts HOT 4
- Support for extra-opts HOT 1
- Multiple calls of a guarded() function retain output HOT 1
- Runtime singleton should be refactored out
- Duplicated text in docstring in state.py
- class Resource should be reimplemented as an actual Abstract Base Class
- Class Context should be reimplemented as an actual Abstract Base Class
- Class Summary could be reimplemented as an actual Abstract Base Class
- Performance class should be a dataclass HOT 1
- Accessing results.by_state creates empty list and corrupts results.most_significant_state HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nagiosplugin.