forked from bortzmeyer/check_expire
Compare commits
No commits in common. "79032c1021773f374eacea008ed7108f709f2e93" and "5c8a6af546861baba88eb0e950a8369d0250a9a9" have entirely different histories.
79032c1021
...
5c8a6af546
24
README.md
24
README.md
|
@ -10,7 +10,6 @@ check_expire follows the usual Nagios rules. The options are:
|
||||||
* -c: critical threshold in days
|
* -c: critical threshold in days
|
||||||
* -w: warning threshold in days
|
* -w: warning threshold in days
|
||||||
* -v: verbose details in output
|
* -v: verbose details in output
|
||||||
* -u: unixtime output
|
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
|
@ -38,8 +37,8 @@ object CheckCommand "expiration" {
|
||||||
apply Service "expiration" {
|
apply Service "expiration" {
|
||||||
import "generic-service"
|
import "generic-service"
|
||||||
|
|
||||||
check_command = "expiration"
|
check_command = "expiration"
|
||||||
|
|
||||||
assign where host.address && host.vars.monitor_expiration
|
assign where host.address && host.vars.monitor_expiration
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
@ -49,26 +48,15 @@ And a possible use:
|
||||||
```
|
```
|
||||||
object Host "bortzmeyer-org" {
|
object Host "bortzmeyer-org" {
|
||||||
...
|
...
|
||||||
|
|
||||||
address = "bortzmeyer.org"
|
address = "bortzmeyer.org"
|
||||||
|
|
||||||
vars.monitor_expiration = true
|
vars.monitor_expiration = true
|
||||||
vars.expiration_verbose = true
|
vars.expiration_verbose = true
|
||||||
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
## Zabbix configuration
|
|
||||||
|
|
||||||
For monitoring systems that do not rely on exit codes but on calculation mechanism based on the metric they receive you can use the `-u` option that will only return the expiration date in unixtime format.
|
|
||||||
|
|
||||||
For instance, you can use the following in zabbix 5.4:
|
|
||||||
|
|
||||||
* item: `check_expire["-H","{HOST.CONN}","-u"]`
|
|
||||||
* trigger (30 days before expiration): `last(/check_expire["-H","{HOST.CONN}","-u"])-now()<2592000`
|
|
||||||
|
|
||||||
Where `2592000` is the number of seconds in 30 days.
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
GPL. See LICENSE.
|
GPL. See LICENSE.
|
||||||
|
@ -79,4 +67,6 @@ Stéphane Bortzmeyer <stephane+chapril@bortzmeyer.org>.
|
||||||
|
|
||||||
## Reference site
|
## Reference site
|
||||||
|
|
||||||
https://forge.chapril.org/bortzmeyer/check_expire Use the Gitea issue tracker to report bugs or wishes.
|
https://forge.chapril.org/bortzmeyer/check_expire Use the Gitea issue tracker to report bugs or wishes.
|
||||||
|
|
||||||
|
|
||||||
|
|
14
check_expire
14
check_expire
|
@ -42,11 +42,10 @@ verbose = False
|
||||||
domain = None
|
domain = None
|
||||||
critical_t = datetime.timedelta(days=2)
|
critical_t = datetime.timedelta(days=2)
|
||||||
warning_t = datetime.timedelta(days=7)
|
warning_t = datetime.timedelta(days=7)
|
||||||
unixtime = False
|
|
||||||
# TODO implement timeout for HTTPS requests. -t option. Does Requests allow it?
|
# TODO implement timeout for HTTPS requests. -t option. Does Requests allow it?
|
||||||
|
|
||||||
def usage(msg=None):
|
def usage(msg=None):
|
||||||
print("Usage: %s -H domain-name [-c critical -w warning -u]" % sys.argv[0], end="")
|
print("Usage: %s -H domain-name [-c critical -w warning]" % sys.argv[0], end="")
|
||||||
if msg is not None and msg != "":
|
if msg is not None and msg != "":
|
||||||
print(" (%s)" % msg)
|
print(" (%s)" % msg)
|
||||||
else:
|
else:
|
||||||
|
@ -81,8 +80,8 @@ def ok(msg=None):
|
||||||
sys.exit(STATE_OK)
|
sys.exit(STATE_OK)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
optlist, args = getopt.getopt (sys.argv[1:], "c:hH:uvVw:",
|
optlist, args = getopt.getopt (sys.argv[1:], "c:hH:vVw:",
|
||||||
["critical=", "expiration", "help", "unixtime", "verbose", "version", "warning="])
|
["critical=", "expiration", "help", "verbose", "version", "warning="])
|
||||||
for option, value in optlist:
|
for option, value in optlist:
|
||||||
if option == "--critical" or option == "-c":
|
if option == "--critical" or option == "-c":
|
||||||
critical_t = datetime.timedelta(days=int(value))
|
critical_t = datetime.timedelta(days=int(value))
|
||||||
|
@ -98,8 +97,6 @@ try:
|
||||||
sys.exit(STATE_OK)
|
sys.exit(STATE_OK)
|
||||||
elif option == "--warning" or option == "-w":
|
elif option == "--warning" or option == "-w":
|
||||||
warning_t = datetime.timedelta(days=int(value))
|
warning_t = datetime.timedelta(days=int(value))
|
||||||
elif option == "--unixtime" or option == "-u":
|
|
||||||
unixtime = True
|
|
||||||
else:
|
else:
|
||||||
# Should never occur, it is trapped by getopt
|
# Should never occur, it is trapped by getopt
|
||||||
print("Unknown option %s" % option)
|
print("Unknown option %s" % option)
|
||||||
|
@ -139,9 +136,6 @@ for event in rdap["events"]:
|
||||||
print("No recognized format for datetime \"%s\"" % event["eventDate"])
|
print("No recognized format for datetime \"%s\"" % event["eventDate"])
|
||||||
sys.exit(STATE_UNKNOWN)
|
sys.exit(STATE_UNKNOWN)
|
||||||
now = datetime.datetime.now(tz=UTCINFO)
|
now = datetime.datetime.now(tz=UTCINFO)
|
||||||
if unixtime == True:
|
|
||||||
print(int(expiration.strftime("%s")))
|
|
||||||
sys.exit(STATE_OK)
|
|
||||||
if expiration < now:
|
if expiration < now:
|
||||||
error("domain %s is already expired (%s ago)" % (domain, (now-expiration)))
|
error("domain %s is already expired (%s ago)" % (domain, (now-expiration)))
|
||||||
rest = expiration-now
|
rest = expiration-now
|
||||||
|
@ -152,3 +146,5 @@ for event in rdap["events"]:
|
||||||
else:
|
else:
|
||||||
ok("expires in %s." % (rest))
|
ok("expires in %s." % (rest))
|
||||||
error("No expiration found")
|
error("No expiration found")
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue