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 Docker images #1105

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ modules/*
python27
python35
python36
python37

# Logs and databases #
######################
Expand All @@ -27,9 +28,10 @@ python36

# Docker files #
################
docker/.env
docker/data/mongodb/*
docker/data/alignak/run/*.pid
docker/data/alignak/log/*.pid
docker/data/alignak/log/*.log
docker/data/alignak/retention/*.json

# OS generated files #
Expand Down
2 changes: 1 addition & 1 deletion alignak/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,13 @@
import sys
import time
import json
import tempfile
import resource
import socket
import signal
from copy import copy
import threading
import logging
import tempfile
import warnings
import traceback
from queue import Empty, Full
Expand Down
2 changes: 1 addition & 1 deletion alignak/external_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ def add_host_comment(self, host, author, comment):
% (host.get_name(), author, comment))

self.send_an_element(brok)
self.send_an_element(comm.get_comment_brok(self.hosts[host].get_name()))
self.send_an_element(comm.get_comment_brok(host.get_name()))

def acknowledge_svc_problem(self, service, sticky, notify, author, comment):
"""Acknowledge a service problem
Expand Down
13 changes: 3 additions & 10 deletions alignak/objects/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@
import logging
from alignak.misc.serialization import unserialize
from alignak.objects.item import Item
from alignak.objects.notificationway import NotificationWay
from alignak.objects.commandcallitem import CommandCallItems

from alignak.util import strip_and_uniq
from alignak.property import (BoolProp, IntegerProp, StringProp, ListProp,
DictProp, FULL_STATUS, CHECK_RESULT)
from alignak.log import make_monitoring_log
from alignak.objects.notificationway import NotificationWay

logger = logging.getLogger(__name__) # pylint: disable=invalid-name

Expand Down Expand Up @@ -177,13 +177,6 @@ class Contact(Item):
'contact_name'
)

simple_way_parameters = (
'service_notification_period', 'host_notification_period',
'service_notification_options', 'host_notification_options',
'service_notification_commands', 'host_notification_commands',
'min_business_impact'
)

def __init__(self, params, parsing=True):
# When deserialized, those are dict
if not parsing:
Expand Down Expand Up @@ -320,8 +313,8 @@ def want_host_notification(self, notifways, timeperiods, timestamp, state, n_typ
def get_notification_commands(self, notifways, n_type, command_name=False):
"""Get notification commands for object type

:param notifways: list of alignak.objects.NotificationWay objects
:type notifways: NotificationWays
:param notifways: list of notification ways objects
:type notifways: alignak.objects.notificationway.NotificationWays
:param n_type: object type (host or service)
:type n_type: string
:param command_name: True to update the inner property with the name of the command,
Expand Down
5 changes: 3 additions & 2 deletions alignak/objects/notificationway.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

from alignak.property import IntegerProp, StringProp, ListProp, FULL_STATUS
from alignak.commandcall import CommandCall
from alignak.misc.serialization import serialize

logger = logging.getLogger(__name__) # pylint: disable=invalid-name

Expand Down Expand Up @@ -154,11 +155,11 @@ def serialize(self, no_json=True, printing=False):
res = super(NotificationWay, self).serialize()

res['service_notification_commands'] = \
[elem.serialize(no_json=no_json, printing=printing)
[serialize(elem, no_json=no_json, printing=printing)
for elem in getattr(self, 'service_notification_commands')]

res['host_notification_commands'] = \
[elem.serialize(no_json=no_json, printing=printing)
[serialize(elem, no_json=no_json, printing=printing)
for elem in getattr(self, 'host_notification_commands')]

return res
Expand Down
2 changes: 1 addition & 1 deletion alignak/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def jsonify_r(obj, running_properties=False,
if prop in filtered_properties:
prop = '_' + prop

# Maybe the property is not jsonable
# Maybe the property is not json-able
try:
if isinstance(val, set):
val = list(val)
Expand Down
90 changes: 90 additions & 0 deletions docker/.env.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
PYTHON_BASE_VERSION=3.6
ALIGNAK_IMAGE_TAG=0.0.1

DOCKER_USER=username
DOCKER_PASS=password

DOCKER_REPOSITORY=alignak
DOCKER_SERVICE=alignak
DOCKER_SERVICE_UI=alignak-ui

ALIGNAK_GIT_REPO=Alignak-monitoring/alignak
# Web UI version: develop (old) or integ (the most recent!)
SHINKEN_WEBUI_VERSION=integ

PYTHONPATH=/shinken_modules

# Shared with the host
ALIGNAK_DATADIR=./data/alignak

# In the container
ALIGNAK_SHARE_DIR=/alignak
ALIGNAK_LOG_DIR=/alignak/log
ALIGNAK_RUN_DIR=/alignak/run
ALIGNAK_ETC_DIR=/alignak/etc
ALIGNAK_CONFIGURATION_FILE=/alignak/etc/alignak.ini

####################
# Alignak configuration
####################
# Use Shinken Web UI as the Alignak UI
ALIGNAK_DAEMON=yes
ALIGNAK_UI_DEBUG=yes
# Or:
#SHINKEN_UI_DEBUG=yes

# Alignak retention module configuration
# Override module configuration file!
ALIGNAK_RETENTION_DIR=/alignak/retention

# Alignak logging more information
#ALIGNAK_LOG_ACTIONS=WARNING
#ALIGNAK_LOG_ALERTS=WARNING
#ALIGNAK_LOG_CHECKS=1
#ALIGNAK_LOG_ACTIVITY=3600

####################
# Graphite configuration
####################
GRAPHITE_DATADIR=./data/graphite

# Tuning - much more is available, see: https://github.com/graphite-project/docker-graphite-statsd
GRAPHITE_WSGI_PROCESSES=4
GRAPHITE_WSGI_THREADS=2
GRAPHITE_WSGI_REQUEST_TIMEOUT=65
GRAPHITE_WSGI_MAX_REQUESTS=1000
GRAPHITE_WSGI_REQUEST_LINE=0

# Log
GRAPHITE_LOG_ROTATION=true
GRAPHITE_LOG_ROTATION_COUNT=1
GRAPHITE_LOG_RENDERING_PERFORMANCE=true
GRAPHITE_LOG_CACHE_PERFORMANCE=true

GRAPHITE_DEBUG=false

COLLECTD=1

####################
# MongoDB variables
####################
MONGO_DATADIR=./data/mongodb

# Create a super-user on first database launch
# Disabled!
MONGO_INITDB_ROOT_USERNAME=
MONGO_INITDB_ROOT_PASSWORD=
# Database selected for startup scripts
MONGO_INITDB_DATABASE=alignak

####################
# Mongo express configuration
####################
ME_CONFIG_MONGODB_SERVER=mongodb
ME_CONFIG_MONGODB_ENABLE_ADMIN=true
# Disabled!
ME_CONFIG_MONGODB_ADMINUSERNAME=
ME_CONFIG_MONGODB_ADMINPASSWORD=
ME_CONFIG_OPTIONS_EDITORTHEME=ambiance
ME_CONFIG_BASICAUTH_USERNAME=admin
ME_CONFIG_BASICAUTH_PASSWORD=admin
84 changes: 84 additions & 0 deletions docker/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!make
# Specify a shell
SHELL := /bin/bash

.PHONY: help

# Create the .env file if it does not exist
ifeq (,$(wildcard .env))
$(shell cp .env.dist .env)
endif
# Get the environment variables
include .env

ifndef ALIGNAK_IMAGE_TAG
$(error The image TAG variable (ALIGNAK_IMAGE_TAG) is missing.)
endif

# Default values for the image
PYTHON_BASE_VERSION ?= 3.6
DOCKER_REPOSITORY ?= alignak
DOCKER_ALIGNAK_DAEMON ?= alignak
DOCKER_ALIGNAK_WEBUI ?= alignak-ui
DOCKER_IMAGE_DAEMON ?= $(DOCKER_REPOSITORY)/$(DOCKER_ALIGNAK_DAEMON)
DOCKER_IMAGE_WEBUI ?= $(DOCKER_REPOSITORY)/$(DOCKER_ALIGNAK_WEBUI)

# User credentials from environment
DOCKER_USER := ${DOCKER_USER}
DOCKER_PASS := ${DOCKER_PASS}

# Alignak configuration
ALIGNAK_CONFIGURATION_FILE ?= /alignak/etc/alignak.ini

# --------------------
help: banner
@echo -e "$$(grep -hE '^\S+:.*##' $(MAKEFILE_LIST) | sed -e 's/:.*##\s*/:/' -e 's/^\(.\+\):\(.*\)/\\x1b[36m\1\\x1b[m:\2/' | column -c2 -t -s :)"


# --------------------
banner: ## This help message
@echo -e "--------------------"
@echo -e "\x1b[36mImage\x1b[m:$(DOCKER_IMAGE):$(ALIGNAK_IMAGE_TAG)" | column -c2 -t -s :
@echo -e "--------------------"

build: banner ## Build the image
$(info Building Alignak $(ALIGNAK_IMAGE_TAG) tagged images.)
@docker-compose build
@make -s clean

remove: banner ## Remove image
$(info Removing "$(DOCKER_IMAGE_DAEMON):$(ALIGNAK_IMAGE_TAG)" image...)
@docker rm $(DOCKER_IMAGE_DAEMON):$(ALIGNAK_IMAGE_TAG)
@docker rm $(DOCKER_IMAGE_WEBUI):$(ALIGNAK_IMAGE_TAG)

clean: banner ## Clean all
@docker system prune --volumes --force

start: banner ## Start the services
$(info Starting Alignak...)
@docker-compose up -d

stop: banner ## Stop the services
$(info Stopping Alignak...)
@docker-compose down

restart: ## Stop and start
$(info Restarting Alignak...)
@make -s stop
@make -s start

check: banner ## Check the Alignak configuration
$(info Check the configuration)
docker-compose run arbiter-master alignak-arbiter -V -e $(ALIGNAK_CONFIGURATION_FILE)

push: banner login ## Push the image to the repository
$(info Pushing "$(DOCKER_IMAGE)":"$(ALIGNAK_IMAGE_TAG)" tagged image.)
@docker push $(DOCKER_IMAGE):$(ALIGNAK_IMAGE_TAG)

pull: banner ## Pull the image
$(info Pulling "$(ALIGNAK_IMAGE_TAG)" tagged image.)
@docker pull $(DOCKER_IMAGE):$(ALIGNAK_IMAGE_TAG)

login: banner ## Login to the repository
$(info Login to Docker Hub, user $(DOCKER_USER).)
@docker login -u $(DOCKER_USER) -p $(DOCKER_PASS)
80 changes: 80 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Docker Alignak

## Host / containers shared volume

The *data/alignak* directory is shared between the host system and the running containers. It contains :
- a default test configuration to show how to configure and use some Alignak features
- some commands used to check hosts and services in the default configuration

The default configuration shows how to build an Alignak configuration split in 3 realms. Each realm owns its hosts and they are all monitored in the same Alignak ystem with one Web UI.

Have a look into the configuration for more information -)


## Using the makefile

A GNU makefile exists to help for the most common operations with Alignak Docker images.

The Makefile includes the *.env* file existing in the current directory.

Note: If the *.env* file does not exist, running make will copy the default *.env.dist* file to a new *.env* file.


```bash

# View all the available targets + doc
make

# Build the images
make build
# This will build the images according to the values defined in the .env file

# Clean extra unused images
make clean

# Push an image to your repository
# Direct
TAG=0.0.1 DOCKER_USER=username DOCKER_PASS=password make push

export TAG=0.0.1
export DOCKER_USER=username
export DOCKER_PASS=password
make push
```

## Build and run
You can also use usual docker-compose to build the Alignak images:

```bash
docker-compose build
```

```bash
docker-compose up
```

## Some commands

Check the Alignak configuration:
```bash
docker-compose run arbiter-master
or
make check
```

## Metrics and Graphite

View https://github.com/graphite-project/docker-graphite-statsd

```bash
docker run -d\
--name graphite\
--restart=always\
-p 80:80\
-p 2003-2004:2003-2004\
-p 2023-2024:2023-2024\
-p 8125:8125/udp\
-p 8126:8126\
graphiteapp/graphite-statsd
```

Loading