def apimethod_get_otx_pulse_stats_summary(user): """Get the pulse statistics: #Pulses, #IOCs, Last Updated, #Alarms with Pulses, #Events with Pulses Args: user(string): User Login Returns: success (bool): True if successful, False elsewhere result(dic) : Error message if there was an error or dic with the pulse stats. """ stats = { "pulses": 0, "iocs": 0, "last_updated": "", "alarms": 0, "events": 0 } if apimethod_is_otx_enabled() is False: return False, 'OTX is not activated' try: pulse_db = PulseDB() pulses = pulse_db.get_range(0, -1) del pulse_db #Getting the number of pulses stats['pulses'] = len(pulses) #Counting the number of indicators for each pulse. for p in pulses: stats['iocs'] += len(p.get('indicators')) stats['alarms'] = db_get_otx_alarms(user) stats['events'] = db_get_otx_events(user) except Exception as err: api_log.error("[apimethod_get_otx_pulse_stats] %s" % str(err)) return False, "Error retrieving the Pulse Stats: %s" % str(err) success, last_updated = db_get_config("open_threat_exchange_latest_update") if not success: api_log.error("[apimethod_get_otx_pulse_stats] %s" % str(last_updated)) return False, "Error retrieving the Pulse Stats: %s" % str( last_updated) stats['last_updated'] = last_updated return True, stats
def apimethod_get_pulse_list(page=0, page_row=10): """Returns the list of current_status messages matching the given criteria. Args: page(int) : Page number page_row(int): Number of items per page Returns: A tuple (boolean,data) where the first argument indicates whether the operation went well or not, and the second one contains the data, in case the operation went wll or an error string otherwise """ pulse_list = {"total": 0, "pulses": []} start = page end = start + page_row - 1 try: pulse_db = PulseDB() p_keys = pulse_db.keys() p_vals = pulse_db.get_range(start, end, 'desc') del pulse_db pulses = [] for p in p_vals: pulses.append({ "id": p.get('id'), "name": p.get('name'), "author_name": p.get('author_name'), "created": p.get('created'), "description": p.get('description'), "modified": p.get('modified'), "tags": p.get('tags') }) pulse_list["total"] = len(p_keys) pulse_list["pulses"] = pulses except Exception as err: api_log.error("[apimethod_get_pulse_list] %s" % str(err)) return False, "Error retrieving the Pulse List: %s" % str(err) return True, pulse_list
def apimethod_get_pulse_list(page=0, page_row=10): """Returns the list of current_status messages matching the given criteria. Args: page(int) : Page number page_row(int): Number of items per page Returns: A tuple (boolean,data) where the first argument indicates whether the operation went well or not, and the second one contains the data, in case the operation went wll or an error string otherwise """ pulse_list = {"total": 0, "pulses": []} start = page end = start + page_row - 1 try: pulse_db = PulseDB() p_keys = pulse_db.keys() p_vals = pulse_db.get_range(start, end, 'desc') del pulse_db pulses = [] for p in p_vals: pulses.append({"id": p.get('id'), "name": p.get('name'), "author_name": p.get('author_name'), "created": p.get('created'), "description": p.get('description'), "modified": p.get('modified'), "tags": p.get('tags')}) pulse_list["total"] = len(p_keys) pulse_list["pulses"] = pulses except Exception as err: api_log.error("[apimethod_get_pulse_list] %s" % str(err)) return False, "Error retrieving the Pulse List: %s" % str(err) return True, pulse_list
def apimethod_get_otx_pulse_stats_summary(user): """Get the pulse statistics: #Pulses, #IOCs, Last Updated, #Alarms with Pulses, #Events with Pulses Args: user(string): User Login Returns: success (bool): True if successful, False elsewhere result(dic) : Error message if there was an error or dic with the pulse stats. """ stats = {"pulses": 0, "iocs": 0, "last_updated": "", "alarms": 0, "events": 0} if apimethod_is_otx_enabled() is False: return False, 'OTX is not activated' try: pulse_db = PulseDB() pulses = pulse_db.get_range(0, -1) del pulse_db # Getting the number of pulses stats['pulses'] = len(pulses) # Counting the number of indicators for each pulse. for p in pulses: stats['iocs'] += len(p.get('indicators', {})) stats['alarms'] = db_get_otx_alarms(user) stats['events'] = db_get_otx_events(user) except Exception as err: api_log.error("[apimethod_get_otx_pulse_stats] %s" % str(err)) return False, "Error retrieving the Pulse Stats: %s" % str(err) success, last_updated = db_get_config("open_threat_exchange_latest_update") if not success: api_log.error("[apimethod_get_otx_pulse_stats] %s" % str(last_updated)) return False, "Error retrieving the Pulse Stats: %s" % str(last_updated) stats['last_updated'] = last_updated return True, stats