mirror of https://github.com/MISP/misp-dashboard
new: [updates] Update script - WiP
parent
8869d6ba44
commit
3a1fe9205d
|
@ -37,6 +37,7 @@ directory=logs
|
|||
dispatcher_filename=zmq_dispatcher.log
|
||||
subscriber_filename=zmq_subscriber.log
|
||||
helpers_filename=helpers.log
|
||||
update_filename=updates.log
|
||||
|
||||
[RedisGlobal]
|
||||
host=localhost
|
||||
|
@ -49,6 +50,7 @@ zmq_url=tcp://localhost:50000
|
|||
[RedisLIST]
|
||||
db=3
|
||||
listName=bufferList
|
||||
dbVersion=db_version
|
||||
|
||||
[RedisLog]
|
||||
db=0
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
import redis
|
||||
import os
|
||||
import configparser
|
||||
import logging
|
||||
|
||||
|
||||
configfile = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'config/config.cfg')
|
||||
cfg = configparser.ConfigParser()
|
||||
cfg.read(configfile)
|
||||
serv_log = redis.StrictRedis(
|
||||
host=cfg.get('RedisGlobal', 'host'),
|
||||
port=cfg.getint('RedisGlobal', 'port'),
|
||||
db=cfg.getint('RedisLog', 'db'))
|
||||
serv_redis_db = redis.StrictRedis(
|
||||
host=cfg.get('RedisGlobal', 'host'),
|
||||
port=cfg.getint('RedisGlobal', 'port'),
|
||||
db=cfg.getint('RedisDB', 'db'))
|
||||
serv_list = redis.StrictRedis(
|
||||
host=cfg.get('RedisGlobal', 'host'),
|
||||
port=cfg.getint('RedisGlobal', 'port'),
|
||||
db=cfg.getint('RedisLIST', 'db'))
|
||||
|
||||
# logger
|
||||
# logDir = cfg.get('Log', 'directory')
|
||||
# logfilename = cfg.get('Log', 'update_filename')
|
||||
# logPath = os.path.join(logDir, logfilename)
|
||||
# if not os.path.exists(logDir):
|
||||
# os.makedirs(logDir)
|
||||
# try:
|
||||
# logging.basicConfig(filename=logPath, filemode='a', level=logging.INFO)
|
||||
# except PermissionError as error:
|
||||
# print(error)
|
||||
# print("Please fix the above and try again.")
|
||||
# sys.exit(126)
|
||||
# update_logger = logging.getLogger(__name__)
|
||||
logDir = cfg.get('Log', 'directory')
|
||||
logfilename = cfg.get('Log', 'update_filename')
|
||||
logPath = os.path.join(logDir, logfilename)
|
||||
if not os.path.exists(logDir):
|
||||
os.makedirs(logDir)
|
||||
handler = logging.FileHandler(logPath)
|
||||
formatter = logging.Formatter('%(asctime)s:%(levelname)s:%(name)s:%(message)s')
|
||||
handler.setFormatter(formatter)
|
||||
update_logger = logging.getLogger(__name__)
|
||||
update_logger.setLevel(logging.INFO)
|
||||
update_logger.addHandler(handler)
|
||||
|
||||
|
||||
def check_for_updates():
|
||||
db_version = serv_redis_db.get(cfg.get('RedisDB', 'dbVersion'))
|
||||
db_version = db_version if db_version is not None else 0
|
||||
result = False
|
||||
|
||||
if db_version == 0:
|
||||
result = apply_update_1()
|
||||
|
||||
if result:
|
||||
serv_redis_db.set(cfg.get('RedisDB', 'dbVersion'), db_version+1)
|
||||
update_logger.warning(f'Bumped dbVersion to {db_version+1}')
|
||||
else:
|
||||
update_logger.info('Database up-to-date')
|
||||
|
||||
|
||||
# Data format changed. Wipe the key.
|
||||
def apply_update_1():
|
||||
serv_redis_db.delete('TEMP_CACHE_LIVE:Attribute')
|
||||
log_text = 'Executed update 1. Deleted Redis key `TEMP_CACHE_LIVE:Attribute`'
|
||||
print(log_text)
|
||||
update_logger.info(log_text)
|
||||
return True
|
|
@ -15,6 +15,7 @@ import redis
|
|||
import zmq
|
||||
|
||||
import util
|
||||
import updates
|
||||
from helpers import (contributor_helper, geo_helper, live_helper,
|
||||
trendings_helper, users_helper)
|
||||
|
||||
|
@ -256,6 +257,8 @@ def process_log(zmq_name, event):
|
|||
|
||||
|
||||
def main(sleeptime):
|
||||
updates.check_for_updates()
|
||||
|
||||
numMsg = 0
|
||||
while True:
|
||||
content = serv_list.rpop(LISTNAME)
|
||||
|
|
Loading…
Reference in New Issue