4 years ago
Using API v2
Hi
Can someone point me in the direction of some instructions on how to make API calls with V2 of the API? (Just with a basic example on how the auth is done now etc)
I can find exampl...
def get_devicealert():
value_list = []
cursor = conn.cursor()
#devicealert = chunker(api_instance.get_alert_list,'needMessage:"true", cleared:"*"')
devicealert = chunker(api_instance.get_alert_list,'custom_Columns:"snow_company_sys_id"')
for i in devicealert:
for c in i.items:
print(c.custom_columns)
query = """INSERT INTO LMDeviceAlert(Internal_ID, chain,id, Monitor_Object_ID, Monitor_Oobject_Name, Monitor_Object_Type, [Rule], Rule_ID, Severity, Start_Epoch, End_Epoch, Acked_Epoch, Alert_Value, Ack_Comment, Acked, Instance_ID, Instance_Name, SDT, Detail_Message)
values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)"""
value = (
i.internal_id,
i.chain,
i.id,
i.monitor_object_id,
i.monitor_object_name,
i.monitor_object_type,
i.rule,
i.rule_id,
#The alert severity, where 2=warning, 3=error and 4=critical
i.severity,
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(i.start_epoch)),
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(i.end_epoch)),
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(i.acked_epoch)),
i.alert_value.replace("'", ""),
i.ack_comment,
i.acked,
i.instance_id,
i.instance_name,
str(i.sdt).replace("'", ""),
str(i.detail_message).replace("'", "")
)
value_list.append(value)
try:
cursor.executemany(query, value_list)
conn.commit()
except:
print('DevicesAlert\nQuery={}\n'.format(query, value_list))
logging.exception('DevicesAlert\nQuery={}\n'.format(value))
cursor.close()
I may have the placement wrong, but the error is "Alert' object has no attribute 'items. Chunker is a function that executes the call until all records are obtained and exists to address the 1k record limit.