From e1c5c9ba4f44c3adc175421995e7171b6122b126 Mon Sep 17 00:00:00 2001 From: diazb Date: Tue, 8 May 2018 14:16:40 -0300 Subject: [PATCH] [PM] Adds support for logstash [PM] Modifies Dockerfile to optimize use of cache [MON] Fixes py3 compatibility issue in Aodh notifier [MON] Removes use of sudo in vrops webservice script Signed-off-by: diazb Change-Id: I93b4bb57f49238a57067cf035509c3e62da5ec2a --- osm_mon/plugins/OpenStack/Aodh/notifier.py | 4 +--- .../vRealiseOps/vROPs_Webservice/install.sh | 4 ++-- policy_module/Dockerfile | 17 ++++++++++------- .../cmd/policy_module_agent.py | 9 +++++++++ policy_module/osm_policy_module/core/config.py | 8 +++++++- policy_module/requirements.txt | 5 +++-- policy_module/scripts/gen_config_from_env.sh | 7 +++++++ 7 files changed, 39 insertions(+), 15 deletions(-) diff --git a/osm_mon/plugins/OpenStack/Aodh/notifier.py b/osm_mon/plugins/OpenStack/Aodh/notifier.py index 55178fd..f7d50a8 100644 --- a/osm_mon/plugins/OpenStack/Aodh/notifier.py +++ b/osm_mon/plugins/OpenStack/Aodh/notifier.py @@ -61,7 +61,6 @@ class NotifierHandler(BaseHTTPRequestHandler): def do_GET(self): """Get request functionality.""" self._set_headers() - self.wfile.write("

hi!

") def do_POST(self): """POST request function.""" @@ -74,7 +73,6 @@ class NotifierHandler(BaseHTTPRequestHandler): post_data = post_data.decode() except AttributeError: pass - self.wfile.write("

POST!

") log.info("This alarm was triggered: %s", json.loads(post_data)) # Generate a notify_alarm response for the SO @@ -121,7 +119,7 @@ class NotifierHandler(BaseHTTPRequestHandler): sev=values['severity'], date=a_date, state=values['current'], vim_type="openstack") producer.notify_alarm( - 'notify_alarm', resp_message, 'alarm_response') + 'notify_alarm', resp_message) log.info("Sent an alarm response to SO: %s", resp_message) except Exception as exc: log.exception("Couldn't notify SO of the alarm:") diff --git a/osm_mon/plugins/vRealiseOps/vROPs_Webservice/install.sh b/osm_mon/plugins/vRealiseOps/vROPs_Webservice/install.sh index e81344b..669f0fb 100755 --- a/osm_mon/plugins/vRealiseOps/vROPs_Webservice/install.sh +++ b/osm_mon/plugins/vRealiseOps/vROPs_Webservice/install.sh @@ -58,8 +58,8 @@ apt-get update # To get the latest package lists [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && easy_install -U bottle #required for vmware connector TODO move that to separete opt in install script -sudo pip install --upgrade pip -sudo pip install cherrypy +pip install --upgrade pip +pip install cherrypy echo ' ################################################################# diff --git a/policy_module/Dockerfile b/policy_module/Dockerfile index 8bb614b..6e93b30 100644 --- a/policy_module/Dockerfile +++ b/policy_module/Dockerfile @@ -24,13 +24,16 @@ FROM ubuntu:16.04 LABEL authors="Benjamín Díaz" -ADD . /policy_module - RUN apt-get --yes update \ - && apt-get --yes install software-properties-common python-software-properties \ - && apt-get --yes install git python python-pip sudo libmysqlclient-dev libxext-dev libxrender-dev libxtst-dev \ - && pip install pip==9.0.3 \ - && pip install -r /policy_module/requirements.txt \ - && pip install /policy_module + && apt-get --yes install python3 python3-pip libmysqlclient-dev \ + && pip3 install pip==9.0.3 + +COPY requirements.txt /policy_module/requirements.txt + +RUN pip3 install -r /policy_module/requirements.txt + +COPY . /policy_module + +RUN pip3 install /policy_module CMD bash /policy_module/scripts/gen_config_from_env.sh && osm-policy-agent --config osm_policy_agent.cfg diff --git a/policy_module/osm_policy_module/cmd/policy_module_agent.py b/policy_module/osm_policy_module/cmd/policy_module_agent.py index 53cf969..b9d6ca9 100644 --- a/policy_module/osm_policy_module/cmd/policy_module_agent.py +++ b/policy_module/osm_policy_module/cmd/policy_module_agent.py @@ -24,6 +24,7 @@ import argparse import logging import sys +import logstash from osm_policy_module.core.agent import PolicyModuleAgent from osm_policy_module.core.config import Config @@ -48,10 +49,18 @@ def main(): format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', filemode='a', level=logging.INFO) + if cfg.get('policy_module', 'enable_logstash_handler') == 'true': + logstash_host = cfg.get('policy_module', 'logstash_host') + logstash_port = int(cfg.get('policy_module', 'logstash_port')) + root_logger = logging.getLogger() + root_logger.addHandler(logstash.TCPLogstashHandler(logstash_host, logstash_port, version=1)) + root_logger.info("Logstash handler configured.") log = logging.getLogger(__name__) + log.info("Config: %s", cfg) log.info("Syncing database...") db_manager = DatabaseManager() db_manager.create_tables() + log.info("Database synced correctly.") log.info("Starting policy module agent...") agent = PolicyModuleAgent() agent.run() diff --git a/policy_module/osm_policy_module/core/config.py b/policy_module/osm_policy_module/core/config.py index ea41fc3..9899009 100644 --- a/policy_module/osm_policy_module/core/config.py +++ b/policy_module/osm_policy_module/core/config.py @@ -45,7 +45,10 @@ class Config(object): 'kafka_server_host': '127.0.0.1', 'kafka_server_port': '9092', 'log_dir': 'stdout', - 'log_level': 'INFO' + 'log_level': 'INFO', + 'enable_logstash_handler': 'false', + 'logstash_host': 'logstash', + 'logstash_port': '5000' }, } @@ -65,3 +68,6 @@ class Config(object): return self.config[group] return self.config[group].get(name, default) return default + + def __str__(self): + return str(self.config) diff --git a/policy_module/requirements.txt b/policy_module/requirements.txt index f92cee9..e387896 100644 --- a/policy_module/requirements.txt +++ b/policy_module/requirements.txt @@ -1,5 +1,6 @@ kafka==1.3.* peewee==3.1.* jsonschema==2.6.* -six -pyyaml \ No newline at end of file +six==1.11.* +pyyaml==3.* +python-logstash==0.4.* \ No newline at end of file diff --git a/policy_module/scripts/gen_config_from_env.sh b/policy_module/scripts/gen_config_from_env.sh index fb71c82..3dcaf67 100644 --- a/policy_module/scripts/gen_config_from_env.sh +++ b/policy_module/scripts/gen_config_from_env.sh @@ -9,4 +9,11 @@ if ! [[ -z "${BROKER_URI}" ]]; then PORT=$(echo $BROKER_URI | cut -d: -f2) echo "kafka_server_host=$HOST" >> $CONFIG_FILENAME echo "kafka_server_port=$PORT" >> $CONFIG_FILENAME +fi +if ! [[ -z "${LOGSTASH_URI}" ]]; then + HOST=$(echo $LOGSTASH_URI | cut -d: -f1) + PORT=$(echo $LOGSTASH_URI | cut -d: -f2) + echo "enable_logstash_handler=true" >> $CONFIG_FILENAME + echo "logstash_host=$HOST" >> $CONFIG_FILENAME + echo "logstash_port=$PORT" >> $CONFIG_FILENAME fi \ No newline at end of file -- 2.25.1