From 6a6fdaf8521952bb30b38482e6c6626349855990 Mon Sep 17 00:00:00 2001
From: lazydog <dogtown@mare-system.de>
Date: Wed, 1 Aug 2018 15:03:19 +0200
Subject: [PATCH] shodan query credits now the right api-endpoint

---
 Readme.md             |  2 +-
 cachet_shodan_credits |  4 ++--
 check_shodan_credits  | 46 ++++++++++++++++++++++++++++++++++---------
 3 files changed, 40 insertions(+), 12 deletions(-)

diff --git a/Readme.md b/Readme.md
index c3df0af..c6dc0aa 100644
--- a/Readme.md
+++ b/Readme.md
@@ -19,7 +19,7 @@ execute $check_plugin -h
 - 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
+- cachet_shodan_credits - sends status-report to cachet-metric
 
 
 
diff --git a/cachet_shodan_credits b/cachet_shodan_credits
index bd86d37..db306b1 100755
--- a/cachet_shodan_credits
+++ b/cachet_shodan_credits
@@ -82,7 +82,7 @@ ERROR you need to give all values (k,c,m,u)
   
   
 
-url = "https://api.shodan.io/account/profile?key=%s" % k
+url = "https://api.shodan.io/api-info?key=%s" % k
 shodan_answer = requests.get(url)
 
 
@@ -93,7 +93,7 @@ if shodan_answer.status_code != 200:
   sys.exit(2)
   
 sj = json.loads(shodan_answer.text)
-creditz = sj["credits"] 
+creditz = sj["query_credits"] 
 
 url = "%s/api/v1/metrics/%s/points" % (u, m)
 headers = {
diff --git a/check_shodan_credits b/check_shodan_credits
index d76b1d1..2647f43 100755
--- a/check_shodan_credits
+++ b/check_shodan_credits
@@ -10,6 +10,34 @@
 #    - python-requests, python-simplejson
 #
 #
+#
+# checkcommands.cfg
+#
+#
+#
+#~ define command {
+
+    #~ command_name    check_shodan_credits
+    #~ command_line    $USER1$/check_shodan_credits -k $ARG1$ -D $ARG2$ -w $ARG3$ -c $ARG4$
+
+#~ }
+
+
+#~ services.cfg 
+#~ #
+#~ #
+#~ define  service {
+        #~ hostname                EXTERNAL_API
+        #~ service_description     check_shodan_credits_dev 
+        #~ check_command           check_shodan_credits!DEV!SHODAN_API_KEY!10!2
+        #~ use                     cysmo-service
+        #~ register                1
+        #~ notifications_enabled   1
+        #~ normal_check_interval   10
+        #~ retry_check_interval    5
+        #~ max_check_attempts      3
+
+#~ }
 
 
 
@@ -100,7 +128,7 @@ ERROR you need to give an API-key
   
   
 
-url = "https://api.shodan.io/account/profile?key=%s" % k
+url = "https://api.shodan.io/api-info?key=%s" % k
 shodan_answer = requests.get(url)
 
 if shodan_answer.status_code != 200:
@@ -111,23 +139,23 @@ if shodan_answer.status_code != 200:
   return_exit(return_d)
 
 sj = json.loads(shodan_answer.text)
-if sj["credits"] < c:
+if sj["query_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"]
+  return_d["text"]="Critical, Credits: %s" % sj["query_credits"]
+  return_d["perfdata"]="| credits: %s;" % sj["query_credits"]
 
-elif sj["credits"] < w:
+elif sj["query_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"]
+  return_d["text"]="Warning, Credits: %s" % sj["query_credits"]
+  return_d["perfdata"]="| credits: %s;" % sj["query_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_d["text"]="All OK, Credits: %s" % sj["query_credits"]
+  return_d["perfdata"]="| credits: %s;" % sj["query_credits"]
 
 return_exit(return_d)
   
-- 
GitLab