Skip to content
Snippets Groups Projects
Commit ff38153b authored by lazydog's avatar lazydog
Browse files

cachet_shodan_credits

parent 80d9e41c
Branches
Tags
No related merge requests found
# Dogtown-Nagios-Plugins
(c) copyright 2008-2017 dogtown@mare-system.de
(c) copyright 2008-2018 dogtown@mare-system.de
these plugins are developed and tested using Debian, SLES
these plugins are developed and tested using FreeBSD, Debian, SLES
and RedHat but should work on any modern Unix.
for help see $check_plugin.Readme, if available, or
......@@ -17,6 +18,10 @@ execute $check_plugin -h
- check_mdstat - check status on linux softraid, also alerts on autmated rebuilds
- check_selenium - extract runtime/status-values from selenium-tests
- check_redis - checks and monitors values on a redis_server
- check_shodan_credits - checks how many credits available on a certain account
- cachet_shodan_credits - sends status-report to cahcet-metric
## obsolete / not maintained anymore
......
#!/usr/bin/env python
# (c) copyright 2018 dogtown@mare-system.de
#
# License: GPL v2
#
# dload: https://bitbucket.org/maresystem/dogtown-nagios-plugins
#
#
# requirements:
# - python-requests, python-simplejson
#
#
version = "0.0.5.r2 - alpha - 2018-05-20"
import getopt, sys, time, os, string
import requests
import simplejson as json
import re
def check_shodan_help():
print """
# usage: $0 -k YOUR_SHODAN_API_KEY -c YOUR_CACHET_KEY -m YOUR_CACHET_METRIC -u YOU_CACHET_URL
"""
try:
opts, args = getopt.getopt(sys.argv[1:], "D:k:w:c:m:u:h",
["help", "script", "debug" ])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
check_shodan_help()
sys.exit(2)
k = c = m = u = 0
for o, a in opts:
#print "o :: " + o + " <--> a: " + a
if o in ("-h", "--help"):
check_shodan_help()
sys.exit()
elif o in ("-k", "--key"):
k = a
elif o in ("-c", "--critical"):
c = a
elif o in ("-m", "--metric"):
m = a
elif o in ("-u", "--cachet_url"):
u = a
else:
check_shodan_help()
sys.exit(2)
if k == 0 or c == 0 or m == 0 or u == 0:
print("""
ERROR you need to give all values (k,c,m,u)
""")
check_shodan_help()
sys.exit(2)
url = "https://api.shodan.io/account/profile?key=%s" % k
shodan_answer = requests.get(url)
if shodan_answer.status_code != 200:
print "ERROR. cannot load shodan-status"
print "status-code: %s" % shodan_answer.status_code
print "text: %s" % shodan_answer.text
sys.exit(2)
sj = json.loads(shodan_answer.text)
creditz = sj["credits"]
url = "%s/api/v1/metrics/%s/points" % (u, m)
headers = {
"X-Cachet-Token": c ,
"Content-Type": "application/json;"
}
data = {
"value": creditz
}
r = requests.post(url, headers = headers, json = data)
if r.status_code != 200:
print("CachetOutput Error (status: %s)" % r.status_code)
print (r.text)
sys.exit(2)
else:
# log here
pass
#!/usr/bin/env python
# (c) copyright 2018 dogtown@mare-system.de
#
# License: GPL v2
#
# dload: https://bitbucket.org/maresystem/dogtown-nagios-plugins
#
#
# requirements:
# - python-requests, python-simplejson
#
#
version = "0.0.5.r2 - alpha - 2018-05-20"
import getopt, sys, time, os, string
import requests
import simplejson as json
import re
# run-defaults
debug = "no"
ctype = "status"
# return-defaults
return_d = {}
return_d["status"]="UNKNOWN"
return_d["exit"]=3
return_d["text"]="no return (default)"
return_d["perfdata"]="none"
def return_exit(rd):
print "ShodanCredits %s %s %s %s " % ( D, rd["status"], rd["text"], rd["perfdata"])
sys.exit(rd["exit"])
def check_shodan_help():
print """
# usage: $0 -k YOUR_API_KEY -d Description [ -w INT [ -c INT ]]
"""
try:
opts, args = getopt.getopt(sys.argv[1:], "D:k:w:c:h",
["help", "script", "debug" ])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
check_shodan_help()
sys.exit(2)
w = 10
c = 2
k=0
D=""
for o, a in opts:
#print "o :: " + o + " <--> a: " + a
if o in ("-h", "--help"):
check_shodan_help()
sys.exit()
elif o in ("-k", "--key"):
k = a
elif o in ("-w", "--warning"):
w = int(a)
elif o in ("-c", "--critical"):
c = int(a)
elif o in ("-D", "--Description"):
D = a
else:
check_shodan_help()
sys.exit(2)
if k == 0:
print("""
ERROR you need to give an API-key
""")
check_shodan_help()
sys.exit(2)
url = "https://api.shodan.io/account/profile?key=%s" % k
shodan_answer = requests.get(url)
if shodan_answer.status_code != 200:
return_d["status"]="Error"
return_d["exit"]=3
return_d["text"]="Error in API-Call, HTTPstatus: %s" % shodan_answer.status_code
return_d["perfdata"]=shodan_answer.text
return_exit(return_d)
sj = json.loads(shodan_answer.text)
if sj["credits"] < c:
return_d["status"]="Critical"
return_d["exit"]=2
return_d["text"]="Critical, Credits: %s" % sj["credits"]
return_d["perfdata"]="| credits: %s;" % sj["credits"]
elif sj["credits"] < w:
return_d["status"]="Warning"
return_d["exit"]=1
return_d["text"]="Warning, Credits: %s" % sj["credits"]
return_d["perfdata"]="| credits: %s;" % sj["credits"]
else:
return_d["status"]="Ok"
return_d["exit"]=0
return_d["text"]="All OK, Credits: %s" % sj["credits"]
return_d["perfdata"]="| credits: %s;" % sj["credits"]
return_exit(return_d)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment