Last active
December 4, 2021 17:54
-
-
Save Midnex/e46e03e8b0656b76eb3e4ae7d9742aa5 to your computer and use it in GitHub Desktop.
Get the number of Deployableassets in SnipeIT
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 json | |
from collections import Counter | |
import requests as req | |
SNIPE_HEADER = { | |
"Accept": "application/json", | |
"Authorization": "Bearer ", # after ther space in "Bearer " paste your API key | |
} | |
SNIPE_URL = "http://0.0.0.0/api/v1/" # replace IP with domain or ip of snipe server | |
mod_url = f"{SNIPE_URL}hardware" | |
querystring = {"offset": "0", "sort": "name", "order": "asc"} | |
asset_req = req.request("GET", mod_url, headers=SNIPE_HEADER, params=querystring) | |
assets = json.loads(asset_req.text)["rows"] | |
data = [] | |
for asset in assets: | |
if asset["status_label"]["status_meta"] == "deployed": # shows deployed assets. | |
asset_id = asset["id"] | |
category = asset["category"]["name"].strip() | |
data.append(category) | |
print(Counter(data)) | |
# returns a Counter object of all items in a dictionary. |
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 json | |
import requests as req | |
SNIPE_HEADER = { | |
"Accept": "application/json", | |
"Authorization": "Bearer ", # after ther space in "Bearer " paste your API key | |
} | |
SNIPE_URL = "http://0.0.0.0/api/v1/" # replace IP with domain or ip of snipe server | |
mod_url = f"{SNIPE_URL}hardware" | |
querystring = {"offset": "0", "sort": "id", "order": "asc"} | |
asset_req = req.request("GET", mod_url, headers=SNIPE_HEADER, params=querystring) | |
assets = json.loads(asset_req.text)["rows"] | |
data = [] | |
for asset in assets: | |
asset_tag = asset["asset_tag"] | |
category = asset["category"]["name"].strip() | |
status_name = asset["status_label"]["name"].strip() | |
status_type = asset["status_label"]["status_type"].strip() | |
status_meta = asset["status_label"]["status_meta"].strip() | |
data.append([asset_tag, category, status_name, status_type, status_meta]) | |
with open("assetByCategory.csv", "w") as f: | |
f.write("asset_tag,category,status_name,status_type,status_meta\n") | |
for asset in data: | |
f.write(",".join(asset) + "\n") |
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
if line 21 is changed, possible defaults values [ deployed | deployable | pending | undeployable ] | |
Checked Out: | |
asset["status_label"]["status_meta"] == "deployed" | |
returns: | |
"status_label": {asssetByCategoryCSV | |
"id": 2, | |
"name": "Ready to Deploy", | |
"status_type": "deployable", | |
"status_meta": "deployed" <--- | |
}, | |
Checked In: | |
asset["status_label"]["status_meta"] == "deployable" | |
returns: | |
"status_label": { | |
"id": 2, | |
"name": "Ready to Deploy", | |
"status_type": "deployable", | |
"status_meta": "deployable" <--- | |
}, | |
Pending: | |
asset["status_label"]["status_meta"] == "pending" | |
returns: | |
"status_label": { | |
"id": 1, | |
"name": "Pending", | |
"status_type": "pending", | |
"status_meta": "pending" <--- | |
}, | |
Un-Deployable: | |
asset["status_label"]["status_meta"] == "undeployable" | |
returns: | |
"status_label": { | |
"id": 5, | |
"name": "Defective", | |
"status_type": "undeployable", | |
"status_meta": "undeployable" <--- | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment