mirror of
https://github.com/thannaske/rspamd-influxdb.git
synced 2023-10-10 13:36:59 +02:00
Dropping os module
Add UTF-8 encoding for API response
This commit is contained in:
parent
06c1179bbd
commit
490496ae83
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import json
|
import json
|
||||||
import os
|
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description="rspamd web interface statistic fetcher for InfluxDB usage")
|
parser = argparse.ArgumentParser(description="rspamd web interface statistic fetcher for InfluxDB usage")
|
||||||
@ -21,20 +20,20 @@ try:
|
|||||||
resp = urllib.request.urlopen(fetch_url)
|
resp = urllib.request.urlopen(fetch_url)
|
||||||
except Exception:
|
except Exception:
|
||||||
print("Could not send GET request to given URL. Check url parameter!")
|
print("Could not send GET request to given URL. Check url parameter!")
|
||||||
os.exit(1)
|
exit(1)
|
||||||
|
|
||||||
# Authorization failed
|
# Authorization failed
|
||||||
if resp.code == 403:
|
if resp.code == 403:
|
||||||
print("Authorization with rspamd web interface failed. Check password parameter!")
|
print("Authorization with rspamd web interface failed. Check password parameter!")
|
||||||
os.exit(1)
|
exit(1)
|
||||||
|
|
||||||
elif resp.code == 404:
|
elif resp.code == 404:
|
||||||
print("HTTP server returned HTTP status code 404. Check url parameter!")
|
print("HTTP server returned HTTP status code 404. Check url parameter!")
|
||||||
os.exit(1)
|
exit(1)
|
||||||
|
|
||||||
elif resp.code == 200:
|
elif resp.code == 200:
|
||||||
# Successful call
|
# Successful call
|
||||||
json = json.loads(resp.read())
|
json = json.loads(resp.read().decode('utf-8'))
|
||||||
|
|
||||||
action_reject = str(json["actions"]["reject"]) + "i"
|
action_reject = str(json["actions"]["reject"]) + "i"
|
||||||
action_soft_reject = str(json["actions"]["soft reject"]) + "i"
|
action_soft_reject = str(json["actions"]["soft reject"]) + "i"
|
||||||
@ -81,9 +80,9 @@ elif resp.code == 200:
|
|||||||
stat_total_learns,
|
stat_total_learns,
|
||||||
stat_fuzzy_rspamd))
|
stat_fuzzy_rspamd))
|
||||||
|
|
||||||
os.exit(0)
|
exit(0)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Web request returned unhandled HTTP status code " + str(resp.code) + ". Please open an issue at GitHub "
|
print("Web request returned unhandled HTTP status code " + str(resp.code) + ". Please open an issue at GitHub "
|
||||||
"with further details.")
|
"with further details.")
|
||||||
os.exit(1)
|
exit(1)
|
||||||
|
Loading…
Reference in New Issue
Block a user