Created
January 11, 2023 17:41
-
-
Save superducktoes/b18e4299254e97eb2fcec867fb700fa6 to your computer and use it in GitHub Desktop.
plot last_seen for GreyNoise query
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
import requests | |
import json | |
GN_API_KEY = "" | |
GN_QUERY = 'jira last_seen:30d' | |
GN_QUERY_URL = "https://api.greynoise.io/v2/experimental/gnql" | |
HEADERS = { | |
"accept": "application/json", | |
"key": GN_API_KEY | |
} | |
PARAMS = { | |
"query": GN_QUERY, | |
"size": "100", | |
"scroll": "" | |
} | |
graphing_results = {} | |
r = requests.get(GN_QUERY_URL, headers=HEADERS, params=PARAMS).json() | |
for i in r["data"]: | |
if i["last_seen"] not in graphing_results: | |
key = i["last_seen"] | |
graphing_results[key] = 1 | |
else: | |
key = i["last_seen"] | |
graphing_results[key] = graphing_results[key] + 1 | |
data = np.array(list(graphing_results.items())) | |
fig,ax = plt.subplots(figsize=(20,10)) | |
dates = [x[0] for x in data] | |
values = [x[1] for x in data] | |
ax.plot(dates, values, "o-") | |
ax.set_title("last_seen graphing") | |
fig.autofmt_xdate() | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment