def get_port_attack_count(self, tablename, unit, uom): fromDate = dateTimeUtility.get_begin_date_iso(unit, uom) sql = "select count(distinct session) as total_attacks from %s where %s >= '%s' " %(tablename, self.date_time_field, fromDate) self.log.debug("sql is:" + sql) result = DatabaseHandler().query_db(sql)[0] return int(result['total_attacks'])
def test_get_begin_date_iso(self): # Test with weeks delta = datetime.timedelta(weeks=3) test_date = (datetime.datetime.now() - delta).replace(microsecond=0) expected_iso_date = dateTimeUtility.get_iso_format(test_date) received_iso_date = dateTimeUtility.get_begin_date_iso("weeks", 3) self.assertEqual(received_iso_date, expected_iso_date)
def get_point_list(self, uom, units): begin_date = dateTimeUtility.get_begin_date_iso(uom, units) query_string = ('select lat,long ' 'from (' 'select distinct lat,long,timestamp, ip ' 'from ipInfo ' 'where lat is not null ' 'and long is not null ' 'and datetime(timestamp) > datetime(\'' + begin_date + '\')' ');') connection = sqlite3.connect(self.global_config['Database']['path']) cursor = connection.cursor() return cursor.execute(query_string).fetchall()
def get_json_by_time(self, portnumber, uom, units): begin_date_iso = dateTimeUtility.get_begin_date_iso(uom, units) tableName = self.global_config.get_plugin_config(portnumber)['table'] date_time_field = self.global_config.get_db_datetime_name() # query = query_db("SELECT * FROM %s where (datetime > '%s')" % (tableName, query_date_iso)) queryString = "SELECT * FROM %s where %s >= '%s' order by id, %s" % (tableName, date_time_field, begin_date_iso, date_time_field) #args = (tableName, date_time_field, begin_date_iso) self.log.info("queryString is: " + str(queryString)) #print ("args to use: " + str(args)) results = self.query_db(queryString) self.log.debug("results: " + str(results)) return results
def get_unique_ips(self, tablename, unit, uom): fromDate = dateTimeUtility.get_begin_date_iso(unit, uom) sql = "select count(distinct peerAddress) as unique_ips from %s where %s >= '%s' " % (tablename, self.date_time_field, fromDate) self.log.debug("sql is:" + sql) result = DatabaseHandler().query_db(sql)[0] return int(result['unique_ips'])