Open joepitt91 opened 4 years ago
Correction, auditing via the API with location_id
set does not update the location of the asset either.
Out of curiosity, do you have an interval set under your "Notification" settings?
As for the location. The location does not update, at this time, when you enter a location for the audit. The current location field is it just make a note of it's current location when the audit was performed.
It does appear that in version 5 that there is a checkbox option to update the location but I don't know if it will be available in the initial v5 release or not.
On notifications page, I have these audit settings:
Auditing via WebUI sets next audit to 24 months time.
Ref location, I'm now doing calls to these endpoints to audit, get ID of and then move the assets:
/api/v1/hardware/audit
/api/v1/hardware/bytag/
/api/v1/hardware/
setting rtd_location_id
to the audit location id.Is this still relevant? We haven't heard from anyone in a bit. If so, please comment with any updates or additional detail. This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Don't take it personally, we just need to keep a handle on things. Thank you for your contributions!
Same issue here, since bulk audit on webui is designed for barcode scanners and multiple devices cannot be audited the same time, workaround would be via api but this is kinda flawed
Edit: You can use put method to change the next audit date to whatever your policy defines. I wrote a python script that reads asset tags from a file, audits them one by one then sets the next audit date, for me its 1 year from the current date. If anyone's in the same shoes let me know and i will share the script
Okay, it looks like this issue or feature request might still be important. We'll re-open it for now. Thank you for letting us know!
Same issue here, since bulk audit on webui is designed for barcode scanners and multiple devices cannot be audited the same time, workaround would be via api but this is kinda flawed
Edit: You can use put method to change the next audit date to whatever your policy defines. I wrote a python script that reads asset tags from a file, audits them one by one then sets the next audit date, for me its 1 year from the current date. If anyone's in the same shoes let me know and i will share the script
I'd love to see what you came up with -- I'm working on a project to normalize audit dates by each location and this could be pretty useful to look at.
here you go:
import requests
import json
from datetime import datetime, timedelta
import time
#THIS SCRIPT AUDITS IN SNIPEIT, SETS AUDIT NOTE TO: "yournote" AND SETS NEXT AUDIT DATE TO + 1 YEAR, READS ASSET_TAGS FROM FILE
# Variables
AUDIT_API_URL = 'https://yoursnipeit.url/api/v1/hardware/audit'
ASSET_API_URL = 'https://yoursnipeit.url/api/v1/hardware'
API_KEY = 'yourapikey'
# Getting asset_tags from a file
def read_asset_tags(file_path):
with open(file_path, 'r') as file:
return [line.strip() for line in file.readlines()]
# Defining path to file
ASSET_TAGS_FILE = 'asset_tags.txt'
# Making a list of asset_tags
ASSET_TAGS = read_asset_tags(ASSET_TAGS_FILE)
# Create the headers for the request
headers = {
'Authorization': f'Bearer {API_KEY}',
'Content-Type': 'application/json'
}
for asset_tag in ASSET_TAGS:
print(f"Processing asset tag: {asset_tag}")
# Create the body of the audit request
audit_data = {
'name': f'Audit for {asset_tag}',
'asset_tag': asset_tag,
'type': 'audit',
'action': 'audit',
'note': 'yournote'
}
# Send the POST request to create an audit record
audit_response = requests.post(AUDIT_API_URL, headers=headers, json=audit_data)
# Check the response
if audit_response.status_code == 200:
print(f'Audit record created successfully for asset tag {asset_tag}.')
else:
print(f'Failed to create audit record for asset tag {asset_tag}. Status code: {audit_response.status_code}')
continue # Skip to the next asset tag if auditing fails
# Wait for 1 second
time.sleep(1)
# Calculate the next audit date (current date + 1 year)
next_audit_date = (datetime.now() + timedelta(days=365)).strftime('%Y-%m-%d')
# Get the asset ID by asset tag
assets_response = requests.get(f'{ASSET_API_URL}?search={asset_tag}', headers=headers)
# Check the response
if assets_response.status_code == 200:
assets = assets_response.json()
if assets['total'] > 0:
asset_id = assets['rows'][0]['id']
print(f'Found asset ID {asset_id} for asset tag {asset_tag}.')
else:
print(f'Asset not found for asset tag {asset_tag}.')
continue # Skip to the next asset tag if the asset is not found
else:
print(f'Failed to retrieve asset information for asset tag {asset_tag}. Status code: {assets_response.status_code}')
continue # Skip to the next asset tag if retrieving asset information fails
# Wait for 1 second
time.sleep(1)
# Create the body of the update request
update_data = {
'next_audit_date': next_audit_date
}
# Send the PUT request to update the next audit date
update_response = requests.put(f'{ASSET_API_URL}/{asset_id}', headers=headers, json=update_data)
# Check the response
if update_response.status_code == 200:
print(f'Next audit date set to {next_audit_date} for asset tag {asset_tag}.')
else:
print(f'Failed to set next audit date for asset tag {asset_tag}. Status code: {update_response.status_code}')
Please confirm you have done the following before posting your bug report:
Describe the bug When auditing assets via POST to the API endpoint
/api/v1/hardware/audit
the last audit date and location are correctly recorded, however, the next audit date is set to NULL, with nothing logged instorage/logs/laravel.log
, including with Advanced DebuggingAPP_DEBUG=true
enabled.To Reproduce Steps to reproduce the behavior:
/api/v1/hardware/audit
Endpoint with theasset_tag
andlocation_id
values set in the body/hardware/360
and notice audit time has updated and next audit time is gone./hardware/360
and notice audit time has updated and next audit time is back.Expected behavior The next audit date should be set as per it is stated as being set in the API response body.
Screenshots
API response
Server (please complete the following information):
Desktop (please complete the following information):
Error Messages
No errors, API Response is HTTP 200, and says next audit has been set.
Additional context