summaryrefslogtreecommitdiffstats
path: root/dashboard/dashboard/common
diff options
context:
space:
mode:
Diffstat (limited to 'dashboard/dashboard/common')
-rw-r--r--dashboard/dashboard/common/__init__.py0
-rw-r--r--dashboard/dashboard/common/elastic_access.py51
-rw-r--r--dashboard/dashboard/common/logger_utils.py64
3 files changed, 0 insertions, 115 deletions
diff --git a/dashboard/dashboard/common/__init__.py b/dashboard/dashboard/common/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/dashboard/dashboard/common/__init__.py
+++ /dev/null
diff --git a/dashboard/dashboard/common/elastic_access.py b/dashboard/dashboard/common/elastic_access.py
deleted file mode 100644
index eb29ce8..0000000
--- a/dashboard/dashboard/common/elastic_access.py
+++ /dev/null
@@ -1,51 +0,0 @@
-import json
-import urlparse
-
-import urllib3
-
-http = urllib3.PoolManager()
-
-
-def _request(method, url, creds=None, body=None):
- headers = urllib3.make_headers(basic_auth=creds)
- return http.request(method, url, headers=headers, body=body)
-
-
-def _post(url, creds=None, body=None):
- return _request('POST', url, creds=creds, body=body)
-
-
-def _get(url, creds=None, body=None):
- return json.loads(_request('GET', url, creds=creds, body=body).data)
-
-
-def delete_docs(url, creds=None, body=None):
- return _request('DELETE', url, creds=creds, body=body)
-
-
-def publish_docs(url, creds=None, body=None):
- result = _post(url, creds=creds, body=(json.dumps(body)))
- return result.status, result.data
-
-
-def _get_docs_nr(url, creds=None, body=None):
- res_data = _get('{}/_search?size=0'.format(url), creds=creds, body=body)
- print(type(res_data), res_data)
- return res_data['hits']['total']
-
-
-def get_docs(url, creds=None, body=None, field='_source'):
-
- docs_nr = _get_docs_nr(url, creds=creds, body=body)
- res_data = _get('{}/_search?size={}'.format(url, docs_nr),
- creds=creds, body=body)
-
- docs = []
- for hit in res_data['hits']['hits']:
- docs.append(hit[field])
- return docs
-
-
-def publish_kibana(url, creds, type, id, body):
- url = urlparse.urljoin(url, '/.kibana/{}/{}'.format(type, id))
- publish_docs(url, creds, body)
diff --git a/dashboard/dashboard/common/logger_utils.py b/dashboard/dashboard/common/logger_utils.py
deleted file mode 100644
index 58e343d..0000000
--- a/dashboard/dashboard/common/logger_utils.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env python
-#
-# feng.xiaowei@zte.com.cn
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Apache License, Version 2.0
-# which accompanies this distribution, and is available at
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Logging levels:
-# Level Numeric value
-# CRITICAL 50
-# ERROR 40
-# WARNING 30
-# INFO 20
-# DEBUG 10
-# NOTSET 0
-#
-# Usage:
-# import functest_logger as fl
-# logger = fl.Logger("script_name").getLogger()
-# logger.info("message to be shown with - INFO - ")
-# logger.debug("message to be shown with - DEBUG -")
-
-import logging
-import os
-
-
-class Logger(object):
- file_path = '/var/log'
- formatter = logging.Formatter('%(asctime)s - %(name)s - '
- '%(levelname)s - %(message)s')
-
- def __init__(self, logger_name):
-
- IF_DEBUG = os.getenv('IF_DEBUG')
-
- self.logger_name = logger_name
- self.logger = logging.getLogger(logger_name)
- self.logger.propagate = 0
- self.logger.setLevel(logging.DEBUG)
-
- ch = logging.StreamHandler()
- ch.setFormatter(self.formatter)
- if IF_DEBUG is not None and IF_DEBUG.lower() == "true":
- ch.setLevel(logging.DEBUG)
- else:
- ch.setLevel(logging.INFO)
- self.logger.addHandler(ch)
-
- hdlr = logging.FileHandler('%s/%s.log' % (self.file_path, logger_name))
- hdlr.setFormatter(self.formatter)
- hdlr.setLevel(logging.DEBUG)
- self.logger.addHandler(hdlr)
-
- @property
- def get(self):
- return self.logger
-
-
-class DashboardLogger(Logger):
- file_path = '/var/log/kibana_dashboard'
-
- def __init__(self, logger_name):
- super(DashboardLogger, self).__init__(logger_name)