Skip to content
Snippets Groups Projects
Verified Commit 5b4bec29 authored by Pavel Břoušek's avatar Pavel Břoušek
Browse files

fix: flake8 violations fixed

parent 6bfa22dd
No related branches found
No related tags found
No related merge requests found
Pipeline #287000 passed with warnings
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
# gustavo chaves for findinx and fixing some bugs # gustavo chaves for findinx and fixing some bugs
# #
# reimplemented by dogtown with more features # reimplemented by dogtown with more features
# adjusted by Perun team to Python3 and support of authentication and unverified SSL usage # adjusted by Perun team to Python3
# and support of authentication and unverified SSL usage
# #
# TODO: # TODO:
# - make -t test1,test2,test available w/ -w 1,2,3 -c 1,2,3 # - make -t test1,test2,test available w/ -w 1,2,3 -c 1,2,3
...@@ -46,9 +47,9 @@ perfdata = "" ...@@ -46,9 +47,9 @@ perfdata = ""
def usage(): def usage():
print( print(
""" """
check_nginx_status.py is a Nagios-Plugin check_nginx_status.py is a Nagios-Plugin
to monitor nginx status and alerts on various values, to monitor nginx status and alerts on various values,
based on teh output from HttpStubStatus - Module based on teh output from HttpStubStatus - Module
it also creates, based on the returned values, a csv to store data it also creates, based on the returned values, a csv to store data
...@@ -56,10 +57,11 @@ it also creates, based on the returned values, a csv to store data ...@@ -56,10 +57,11 @@ it also creates, based on the returned values, a csv to store data
Usage: Usage:
check_nginx_status [-H|--HOST] [-p|--port] [-u|--url] [-U|--user] [-P|--password] [-s|--ssl] check_nginx_status [-H|--HOST] [-p|--port] [-u|--url] [-U|--user] [-P|--password]
[-t|--test] [-w|--warning] [-c|--critical] [-s|--ssl] [-t|--test] [-w|--warning] [-c|--critical]
[-o|--output] [-r|--resultfile][-n|--noresult] [-o|--output] [-r|--resultfile][-n|--noresult]
[-h|--help] [-v|--version] [-d|--debug] [-S|--servername] [-D|--disablesslverifyhostname] [-h|--help] [-v|--version] [-d|--debug] [-S|--servername]
[-D|--disablesslverifyhostname]
Options: Options:
...@@ -72,32 +74,33 @@ Options: ...@@ -72,32 +74,33 @@ Options:
Default: localhost Default: localhost
--SERVERNAME|-S) --SERVERNAME|-S)
(host header of HTTP request) use it if you specified an IP in -H to match the good Virtualhost in your target (host header of HTTP request) use it if you specified an IP in -H
to match the good Virtualhost in your target
--port|-p) --port|-p)
Sets connection-port Sets connection-port
Default: 80/http, 443/https Default: 80/http, 443/https
--ssl|-s) --ssl|-s)
Turns on SSL Turns on SSL
Default: off Default: off
--url|-u) --url|-u)
Sets nginx status url path. Sets nginx status url path.
Default: /nginx_status Default: /nginx_status
--user|-U) --user|-U)
Sets nginx status BasicAuth username. Sets nginx status BasicAuth username.
Default: off Default: off
--password|-P) --password|-P)
Sets nginx status BasicAuth password. Sets nginx status BasicAuth password.
Default: off Default: off
--disablesslverifyhostname|-D) --disablesslverifyhostname|-D)
Do not verify ssl session Do not verify ssl session
Default: off (do verify) Default: off (do verify)
--test|-t) --test|-t)
Sets the test(check)_value for w/c Sets the test(check)_value for w/c
if used, -w/-c is mandatory if used, -w/-c is mandatory
...@@ -105,44 +108,44 @@ Options: ...@@ -105,44 +108,44 @@ Options:
possible Values: possible Values:
active_conns -> active connections active_conns -> active connections
accepts_err -> difference between accepted and accepts_err -> difference between accepted and
handled requests (should be 0) handled requests (should be 0)
requests -> check for requests/connection requests -> check for requests/connection
reading -> actual value for reading headers reading -> actual value for reading headers
writing -> value for active requests writing -> value for active requests
waiting -> actual keep-alive-connections waiting -> actual keep-alive-connections
checktime -> checks if this check need more than checktime -> checks if this check need more than
given -w/-c milliseconds given -w/-c milliseconds
--calculated checks --------------- --calculated checks ---------------
rps -> requests per seconds rps -> requests per seconds
cps -> connections per second cps -> connections per second
dreq -> delta requests to the previous one dreq -> delta requests to the previous one
dcon -> delta connections to the previous one dcon -> delta connections to the previous one
these checks are calculated at runtime with a timeframe these checks are calculated at runtime with a timeframe
between the latest and the current check; time is between the latest and the current check; time is
extracted from the timestamp of the result_file extracted from the timestamp of the result_file
to disable calculation (no files are written) use -n; to disable calculation (no files are written) use -n;
you cannot use -t [rps,cps,dreq,dcon] with -n; this you cannot use -t [rps,cps,dreq,dcon] with -n; this
will raise an error and the plugin returns UNKNOWN will raise an error and the plugin returns UNKNOWN
see -r - option for an alternate filepath for temporary results see -r - option for an alternate filepath for temporary results
--warning|-w) --warning|-w)
Sets a warning level for selected test(check) Sets a warning level for selected test(check)
Default: off Default: off
--critical|-c) --critical|-c)
Sets a critical level for selected test(check) Sets a critical level for selected test(check)
Default: off Default: off
--debug|-d) --debug|-d)
turn on debugging - messages (use this for manual testing, turn on debugging - messages (use this for manual testing,
never via nagios-checks; beware of the messy output never via nagios-checks; beware of the messy output
Default: off Default: off
--version|-v) --version|-v)
display version and exit display version and exit
...@@ -152,32 +155,32 @@ Options: ...@@ -152,32 +155,32 @@ Options:
--resultfile|-r) --resultfile|-r)
/path/to/check_nginx.results{.csv} /path/to/check_nginx.results{.csv}
please note, beside the values from the actual check please note, beside the values from the actual check
(eg.g check_nginx.results) a second (eg.g check_nginx.results) a second
file is created, if not existent, and written on each plugin-run file is created, if not existent, and written on each plugin-run
(check_nginx.results.csv), containign a historic view on all (check_nginx.results.csv), containign a historic view on all
extracted values extracted values
default: /tmp/check_nginx.results{.csv} default: /tmp/check_nginx.results{.csv}
--noresult|-n) --noresult|-n)
never write a results-file; CANNOT be used with calculated checks never write a results-file; CANNOT be used with calculated checks
-t [rps|cps|dreq|dcon] -t [rps|cps|dreq|dcon]
default: off default: off
*** ) -> please dont use this option, not implemented or not functional *** ) -> please dont use this option, not implemented or not functional
Examples: Examples:
just get all perfdata, url is default (/nginx_status) just get all perfdata, url is default (/nginx_status)
./check_nginx_status.py --HOST www.example.com ./check_nginx_status.py --HOST www.example.com
just get active connections perfdata just get active connections perfdata
./check_nginx_status.py -H www.example.com -o ./check_nginx_status.py -H www.example.com -o
check for plugin_checktime, error > 10ms (warning) or 50ms (error) and output check for plugin_checktime, error > 10ms (warning) or 50ms (error) and output
only perfdata for that values only perfdata for that values
./check_nginx_status.py -H www.example.com -u /status -w 10 -c 50 -o ./check_nginx_status.py -H www.example.com -u /status -w 10 -c 50 -o
check for requests per second, alert on > 300/1000 active connections check for requests per second, alert on > 300/1000 active connections
./check_nginx_status.py -H www.example.com -u /status -t rps -w 300 -c 1000 ./check_nginx_status.py -H www.example.com -u /status -t rps -w 300 -c 1000
...@@ -185,8 +188,9 @@ Examples: ...@@ -185,8 +188,9 @@ Examples:
./check_nginx_status.py -H www.example.com -t accepts_err -w 1 -c 50 ./check_nginx_status.py -H www.example.com -t accepts_err -w 1 -c 50
Performancedata: Performancedata:
NginxStatus.Check OK | ac=1;acc=64; han=64; req=64; err=0; rpc=1; rps=0; cps=0; dreq=1; NginxStatus.Check OK | ac=1;acc=64; han=64; req=64; err=0;
rpc=1; rps=0; cps=0; dreq=1;
dcon=1; read=0; writ=1; wait=0; ct=6ms; dcon=1; read=0; writ=1; wait=0; ct=6ms;
ac -> active connections ac -> active connections
...@@ -194,13 +198,14 @@ Performancedata: ...@@ -194,13 +198,14 @@ Performancedata:
han -> totally handled connections han -> totally handled connections
req -> total requests req -> total requests
err -> diff between acc - han, thus errors err -> diff between acc - han, thus errors
rpc -> requests per connection (req/han) rpc -> requests per connection (req/han)
rps -> requests per second (calculated) from last checkrun vs actual values rps -> requests per second (calculated) from last checkrun vs actual values
cps -> connections per (calculated) from last checkrun vs actual values cps -> connections per (calculated) from last checkrun vs actual values
dreq -> request-delta from last checkrun vs actual values dreq -> request-delta from last checkrun vs actual values
dcon -> accepted-connection-delta from last checkrun vs actual values dcon -> accepted-connection-delta from last checkrun vs actual values
read -> reading requests from clients read -> reading requests from clients
writ -> reading request body, processes request, or writes response to a client writ -> reading request body, processes request,
or writes response to a client
wait -> keep-alive connections, actually it is ac - (read + writ) wait -> keep-alive connections, actually it is ac - (read + writ)
ct -> checktime (connection time) for this check ct -> checktime (connection time) for this check
...@@ -208,8 +213,8 @@ Performancedata: ...@@ -208,8 +213,8 @@ Performancedata:
Nginx-Config Nginx-Config
be sure to have your nginx compiled with Status-Module be sure to have your nginx compiled with Status-Module
(--with-http_stub_status_module), you might want to test (--with-http_stub_status_module), you might want to test
your installation with nginx -V your installation with nginx -V
http://wiki.nginx.org/HttpStubStatusModule http://wiki.nginx.org/HttpStubStatusModule
location /nginx_status { location /nginx_status {
...@@ -219,7 +224,7 @@ Nginx-Config ...@@ -219,7 +224,7 @@ Nginx-Config
deny all; deny all;
} }
Requirements: Requirements:
nginx compiled with HttpStubStatusModule (see Nginx-Config) nginx compiled with HttpStubStatusModule (see Nginx-Config)
...@@ -227,7 +232,7 @@ Requirements: ...@@ -227,7 +232,7 @@ Requirements:
Docs & Download: Docs & Download:
https://bitbucket.org/maresystem/dogtown-nagios-plugins https://bitbucket.org/maresystem/dogtown-nagios-plugins
""" """
) )
...@@ -237,9 +242,9 @@ def ver(): ...@@ -237,9 +242,9 @@ def ver():
""" """
check_nginx_status check_nginx_status
version : %s version : %s
usage : check_nginx_status -h usage : check_nginx_status -h
""" """
% version % version
) )
...@@ -320,20 +325,8 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct): ...@@ -320,20 +325,8 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct):
f = open(result_file, "r") f = open(result_file, "r")
ro = f.readline().split(";") ro = f.readline().split(";")
f.close() f.close()
o_ac = int(ro[0])
o_acc = int(ro[1]) o_acc = int(ro[1])
o_han = int(ro[2])
o_req = int(ro[3]) o_req = int(ro[3])
o_err = int(ro[4])
o_rpc = int(ro[5])
o_rps = int(ro[6])
o_cps = int(ro[7])
o_dreq = int(ro[8])
o_dcon = int(ro[9])
o_read = int(ro[10])
o_writ = int(ro[11])
o_wait = int(ro[12])
o_ct = int(ro[13])
last = int(os.path.getmtime(result_file)) last = int(os.path.getmtime(result_file))
dtime = now - last dtime = now - last
if req >= o_req: if req >= o_req:
...@@ -347,7 +340,7 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct): ...@@ -347,7 +340,7 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct):
dcon = acc dcon = acc
cps = int(dcon / dtime) cps = int(dcon / dtime)
except: except OSError:
print_debug( print_debug(
"cannot read/process result_file :: %s \n use -r" % result_file "cannot read/process result_file :: %s \n use -r" % result_file
) )
...@@ -356,8 +349,8 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct): ...@@ -356,8 +349,8 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct):
else: else:
if test in ("rps", "cps", "dreq", "dcon"): if test in ("rps", "cps", "dreq", "dcon"):
print( print(
"NginxStatus.%s UNKNONW - noresult selected (-n), cannot calculate test_results" "NginxStatus.%s UNKNONW" % (test)
% (test) + " - noresult selected (-n), cannot calculate test_results"
) )
sys.exit(3) sys.exit(3)
...@@ -372,7 +365,7 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct): ...@@ -372,7 +365,7 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct):
% (ac, acc, han, req, err, rpc, rps, cps, dreq, dcon, read, writ, wait, ct) % (ac, acc, han, req, err, rpc, rps, cps, dreq, dcon, read, writ, wait, ct)
) )
f.close() f.close()
except: except OSError:
print_debug("cannot create result_file :: %s \n use -r" % result_file) print_debug("cannot create result_file :: %s \n use -r" % result_file)
return (rps, cps, dreq, dcon) return (rps, cps, dreq, dcon)
csv = "%s.csv" % result_file csv = "%s.csv" % result_file
...@@ -381,9 +374,12 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct): ...@@ -381,9 +374,12 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct):
print_debug("creating result_file.csv -> %s" % result_file) print_debug("creating result_file.csv -> %s" % result_file)
f = open(csv, "w") f = open(csv, "w")
f.write( f.write(
""""timestamp"; "active conns"; "accepted"; "handled"; "requests"; "req_errors"; "reqs per conn"; "reqs per sec"; "conns per sec"; "delta reqs"; "delta conns"; "reading"; "writing"; "waiting"; "checktime"; \n""" '"timestamp"; "active conns"; "accepted"; "handled"; "requests";'
+ ' "req_errors"; "reqs per conn"; "reqs per sec"; "conns per sec";'
+ ' "delta reqs"; "delta conns"; "reading"; "writing"; "waiting";'
+ ' "checktime"; \n'
) )
except: except OSError:
print("ERR.cannot create result_file.csv :: %s \n use -r" % csv) print("ERR.cannot create result_file.csv :: %s \n use -r" % csv)
print_debug("writing result_file.csv -> %s.csv" % result_file) print_debug("writing result_file.csv -> %s.csv" % result_file)
...@@ -410,7 +406,7 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct): ...@@ -410,7 +406,7 @@ def calculate(req, acc, ac, han, err, rpc, read, writ, wait, ct):
) )
) )
f.close() f.close()
except: except OSError:
print("ERR.cannot write result_file.csv :: %s \n use -r" % csv) print("ERR.cannot write result_file.csv :: %s \n use -r" % csv)
return (rps, cps, dreq, dcon) return (rps, cps, dreq, dcon)
...@@ -559,9 +555,9 @@ def main(): ...@@ -559,9 +555,9 @@ def main():
print_debug( print_debug(
"""-- status-report (perfdata)--- """-- status-report (perfdata)---
active_conns : %s active_conns : %s
accepted conns : %s accepted conns : %s
handled : %s handled : %s
requests : %s requests : %s
accept_errors : %s accept_errors : %s
...@@ -573,9 +569,9 @@ def main(): ...@@ -573,9 +569,9 @@ def main():
reading : %s reading : %s
writing : %s writing : %s
waiting : %s waiting : %s
checktime : %s ms checktime : %s ms
""" """
% (ac, acc, han, req, err, rpc, rps, cps, dreq, dcon, read, writ, wait, ct) % (ac, acc, han, req, err, rpc, rps, cps, dreq, dcon, read, writ, wait, ct)
) )
...@@ -661,8 +657,10 @@ def main(): ...@@ -661,8 +657,10 @@ def main():
perfdata = "%s=%s;" % (test, ta) perfdata = "%s=%s;" % (test, ta)
else: else:
perfdata = ( perfdata = (
"ac=%s;acc=%s; han=%s; req=%s; err=%s; rpc=%s; rps=%s; cps=%s; dreq=%s; dcon=%s; read=%s; writ=%s; wait=%s; ct=%sms;" "ac=%s;acc=%s; han=%s; req=%s; err=%s; rpc=%s; rps=%s; cps=%s; dreq=%s;"
% (ac, acc, han, req, err, rpc, rps, cps, dreq, dcon, read, writ, wait, ct) % (ac, acc, han, req, err, rpc, rps, cps, dreq)
+ " dcon=%s; read=%s; writ=%s; wait=%s; ct=%sms;"
% (dcon, read, writ, wait, ct)
) )
print_debug("perfdata: %s" % perfdata) print_debug("perfdata: %s" % perfdata)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment