Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WiP: Alignak specific stuff #681

Open
wants to merge 31 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
35cb117
Update test configuration
mohierf Dec 16, 2018
1eab371
Manage Alignak arbiter in the main module - get status thread
mohierf Dec 16, 2018
b397a21
Display Alignak parameters - schedulers configuration
mohierf Dec 16, 2018
f4c4115
Alignak MongoDB logs
mohierf Dec 16, 2018
a594e7c
Alignak system menu with the live state and the events log
mohierf Dec 16, 2018
fe47d22
Alignak statistics - first version
mohierf Dec 17, 2018
ddcfa28
Closes #676 - Contacts list with icon
mohierf Dec 13, 2018
eb8ca94
Fix hostgroups filtering behaviour
mohierf Dec 18, 2018
9b0dc47
Revert some of 1435bdb about comment tab
Dec 18, 2018
445c31d
Closes #696 - fix and improve broken parameters view
mohierf Dec 21, 2018
7aeabc9
Helper functions to render notes and actions
mohierf Dec 19, 2018
cfcd48d
Closes #677 - render notes and actions in the element view
mohierf Dec 20, 2018
0ebc860
Closes #677 - render notes and actions in the problems view
mohierf Dec 20, 2018
c8f7c77
Fix a CSS media query for width around 992px
mohierf Jan 2, 2019
c20d924
Revert "Closes #677 - render notes and actions in the problems view"
Jan 2, 2019
a1bf880
Revert "Closes #677 - render notes and actions in the element view"
Jan 2, 2019
80e58c5
Revert "Helper functions to render notes and actions"
Jan 2, 2019
205edf7
Debug notes_url display in cv_hosts
Jan 2, 2019
0a614a6
Closes #677 - render notes and actions in the element view
mohierf Dec 20, 2018
a6081ca
Helper functions to render notes and actions
mohierf Dec 19, 2018
2d197ff
Closes #699 - enhance plain text search engine
mohierf Dec 21, 2018
8aadced
Improve hovering title (Aka) for host name if host has a display_name
mohierf Dec 28, 2018
e1fbefa
Load shinken-action.js only once!
mohierf Dec 30, 2018
fdcd2eb
Improve Alignak parameters view
mohierf Dec 31, 2018
799b25e
Improve host custom view
mohierf Dec 31, 2018
eae5408
Clean element view and update test configuration
mohierf Dec 31, 2018
292e22b
Alert if user and BIs are not consistent (log + user preference message)
mohierf Dec 18, 2018
aedbfda
Manage BI filter in the search query parameter
mohierf Dec 19, 2018
9e1c187
BI cleaning - review comments
mohierf Dec 31, 2018
48c3e0f
Add a duration check criteria: last_check
mohierf Jan 1, 2019
6c4a73e
Clean the anonymous user mode and the currently view
mohierf Jan 2, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Manage Alignak arbiter in the main module - get status thread
mohierf committed Dec 18, 2018
commit 1eab371c502c75f840908256529d7d259272660f
17 changes: 15 additions & 2 deletions etc/alignak.d/alignak-module-webui.ini
Original file line number Diff line number Diff line change
@@ -13,8 +13,9 @@ python_name=alignak_webui
;log_level=INFO
# Set log_color=1 to have a (colored) log on the console
;log_console=0
# Declare the log file for the Shinken Web UI log (default is /var/log/alignak/shinken-webui.log)
;log_file=/var/log/alignak/shinken-webui.log
# Declare the log file for the Shinken Web UI log (default is /var/log/alignak/alignak-webui.log)
; If the configured and/or default log file is not allowed, the UI will log to /tmp/alignak-webui.log
;log_file=/var/log/alignak/alignak-webui.log

# Export module metrics to a statsd server.
# By default at localhost:8125 (UDP) with the alignak prefix
@@ -26,6 +27,18 @@ python_name=alignak_webui
# Default is not enabled
;statsd_enabled=0

## Alignak configuration
# Define the Alignak arbiter API endppont
;alignak_endpoint = http://127.0.0.1:7770

# The webUI will get the Alignak livestate every alignak_check_period seconds
;alignak_check_period = 10

# The WebUI will store internally an events log queue limited to alignak_events_count items
# If ALIGNAK_EVENTS_LOG_COUNT environment variable is set it will take precedence
;alignak_events_count = 1000


## Modules for WebUI
## User authentication:
# - auth-cfg-password (internal) : Use the password set in Shinken contact for auth.
62 changes: 62 additions & 0 deletions module/module.py
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@
WEBUI_LICENSE = "License GNU AGPL as published by the FSF, minimum version 3 of the License."

import os
import json
import string
import random
import traceback
@@ -46,6 +47,8 @@
import logging
import requests

from collections import deque

try:
from setproctitle import setproctitle
except ImportError as err:
@@ -173,6 +176,14 @@ def __init__(self, modconf):
self.type = 'webui'
self.name = 'webui'

# Configure Alignak Arbiter API endpoint
self.alignak_endpoint = getattr(modconf, 'alignak_endpoint', 'http://127.0.0.1:7770')
self.alignak_check_period = int(getattr(modconf, 'alignak_check_period', '10'))
self.alignak_livestate = {}
self.alignak_events_count = int(getattr(modconf, 'alignak_events_count', '1000'))
self.alignak_events = deque(maxlen=int(os.environ.get('ALIGNAK_EVENTS_LOG_COUNT',
self.alignak_events_count)))

# Shinken logger configuration
log_console = (getattr(modconf, 'log_console', '0') == '1')
if not log_console:
@@ -573,6 +584,11 @@ def main(self):
self.data_thread.start()
# TODO: look for alive and killing

# Launch the Alignak arbiter data thread ...
if self.alignak and self.alignak_endpoint:
self.fmwk_thread = threading.Thread(None, self.fmwk_thread, 'fmwk_hread')
self.fmwk_thread.start()

logger.info("[WebUI] starting Web UI server on %s:%d ...", self.host, self.port)
bottle.TEMPLATES.clear()
webui_app.run(host=self.host, port=self.port, server=self.http_backend, **self.serveropts)
@@ -730,6 +746,52 @@ def manage_brok_thread(self):

logger.debug("[WebUI] manage_brok_thread end ...")

def fmwk_thread(self):
"""A thread function that periodically gets its state from the Alignak arbiter

This function gets Alignak status in our alignak_livestate and
then it gets the Alignak events in our alignak_events queue
"""
logger.debug("[WebUI] fmwk_thread start ...")

req = requests.Session()
alignak_timestamp = 0
while not self.interrupted:
# Get Alignak status
try:
raw_data = req.get("%s/status" % self.alignak_endpoint)
data = json.loads(raw_data.content)
self.alignak_livestate = data.get('livestate', 'Unknown')
logger.debug("[WebUI-fmwk_thread] Livestate: %s", data)
except Exception as exp:
logger.info("[WebUI-system] alignak_status, exception: %s", exp)

try:
# Get Alignak most recent events
# count is the maximum number of events we will be able to get
# timestamp is the most recent event we got
raw_data = req.get("%s/events_log?details=1&count=%d&timestamp=%d"
% (self.alignak_endpoint, self.alignak_events_count, alignak_timestamp))
data = json.loads(raw_data.content)
logger.debug("[WebUI-fmwk_thread] got %d event log", len(data))
for log in data:
# Data contains: {
# u'date': u'2018-11-24 16:28:03', u'timestamp': 1543073283.434844,
# u'message': u'RETENTION LOAD: scheduler-master', u'level': u'info'
# }
alignak_timestamp = max(alignak_timestamp, log['timestamp'])
if log not in self.alignak_events:
logger.debug("[WebUI-fmwk_thread] New event log: %s", log)
self.alignak_events.appendleft(log)
logger.debug("[WebUI-fmwk_thread] %d log events", len(self.alignak_events))
except Exception as exp:
logger.info("[WebUI-system] alignak_status, exception: %s", exp)

# Sleep for a while...
time.sleep(self.alignak_check_period)

logger.debug("[WebUI] fmwk_thread end ...")

# Here we will load all plugins (pages) under the webui/plugins
# directory. Each one can have a page, views and htdocs dir that we must
# route correctly