Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmeggle committed Aug 25, 2021
2 parents 7d2e75e + 4a4a371 commit 65eb3d6
Show file tree
Hide file tree
Showing 20 changed files with 809 additions and 432 deletions.
27 changes: 3 additions & 24 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,37 +1,16 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.155.1/containers/ubuntu/.devcontainer/base.Dockerfile

ARG VARIANT="2.0.0-p4"
FROM checkmk/check-mk-enterprise:${VARIANT}
ARG VARIANT
# FROM checkmk/check-mk-enterprise:${VARIANT}
FROM robotmk-cmk-python3:${VARIANT}
ARG PIP

ENV CMK_PASSWORD="cmk"

# install python3 on the container
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install wget build-essential libreadline-gplv2-dev libncursesw5-dev \
libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev \
&& cd /tmp && wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz \
&& tar xzf Python-3.9.4.tgz \
&& cd Python-3.9.4 \
&& ./configure \
&& make build_all \
&& make install

# install python modules to run the Robotmk plugin in this container
RUN pip3 install robotframework pyyaml mergedeep python-dateutil ipdb

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends jq tree htop vim git telnet file lsyncd

# Creates the OMD site, executes post-start hook and halts before site start
COPY docker-entrypoint.d /docker-entrypoint.d
RUN /docker-entrypoint.sh /bin/true

# ADD requirements.txt /tmp/requirements.txt
# RUN PATH="/omd/sites/cmk/bin:${PATH}" \
# OMD_ROOT="/omd/sites/cmk" \
# /omd/sites/cmk/bin/${PIP} install -r /tmp/requirements.txt

# make the agent dir writeable from the CMK site (to link RF example tests)
RUN chgrp -R cmk /usr/lib/check_mk_agent && chmod g+w /usr/lib/check_mk_agent

Expand Down
19 changes: 19 additions & 0 deletions .devcontainer/Dockerfile_cmk_python
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
ARG VARIANT
FROM checkmk/check-mk-enterprise:$VARIANT

# install python3 on the container
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install wget build-essential libreadline-gplv2-dev libncursesw5-dev \
libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev \
&& cd /tmp && wget https://www.python.org/ftp/python/3.9.4/Python-3.9.4.tgz \
&& tar xzf Python-3.9.4.tgz \
&& cd Python-3.9.4 \
&& ./configure \
&& make build_all \
&& make install

# install python modules to run the Robotmk plugin in this container
RUN pip3 install robotframework pyyaml mergedeep python-dateutil ipdb

RUN export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends jq tree htop vim git telnet file lsyncd
2 changes: 2 additions & 0 deletions .devcontainer/build-devcontainer.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CMKVERSIONS="1.6.0p25
2.0.0p5"
54 changes: 54 additions & 0 deletions .devcontainer/build-devcontainer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash
# This script should be executed at the very beginning to craft Docker images based on
# the original Checkmk 1/2 Docker images which also contain Python 3.9 and Robotframework.
#
# 1) Edit build-devcontainer.env and change the variable CMKVERSIONS to your needs.
# It should only contain CMK versions you want to test/develop on.
# 2) Start build-devcontainer.sh. It will check if the CMK Docker images are already
# available locally. If not, it asks for credentials to download the
# image from the CMK download page.
# 3) After the image tgz has been downloaded, it will be imported into Docker.
# (approx. 5 minutes)
# 4) In the last step, the script will build an image based on the CMK version, including
# Python3 and robotframework. (approx. 10 minutes)
# $ docker images | grep mk
# robotmk-cmk-python3 2.0.0p5 1d96bebf47a6 27 seconds ago 2.18GB
# robotmk-cmk-python3 1.6.0p25 599e8beeb9c7 10 minutes ago 1.93GB


# Name of the resulting images
IMAGE=robotmk-cmk-python3
# load Checkmk versions
. build-devcontainer.env

for VERSION in $CMKVERSIONS; do
docker images | egrep "checkmk/check-mk-enterprise.*$VERSION" 2>&1 > /dev/null
if [ $? -gt 0 ]; then
echo "Docker image checkmk/check-mk-enterprise.*$VERSION is not available locally."
read -p "Download this image? " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then

read -p "Username: " user
DOWNLOAD_FOLDER=$(mktemp -d)
URL=https://download.checkmk.com/checkmk/$VERSION
TGZ=check-mk-enterprise-docker-$VERSION.tar.gz
TGZ_FILE=${DOWNLOAD_FOLDER}/${TGZ}
echo "+ Downloading docker image $VERSION to $DOWNLOAD_FOLDER ..."
wget -P $DOWNLOAD_FOLDER --user $user ${URL}/${TGZ} --ask-password
if [ -f $TGZ_FILE ]; then
echo "+ Importing image $TGZ_FILE ..."
docker load -i $TGZ_FILE
else
echo "ERROR: $TGZ_FILE not found!"
fi
else
continue
fi
fi
echo "----"
echo "Docker image checkmk/check-mk-enterprise.*$VERSION is ready to use"
echo "----"
echo "Building now the image robotmk-cmk-python3:$VERSION from Dockerfile_cmk_python ..."
docker build -t robotmk-cmk-python3:$VERSION -f Dockerfile_cmk_python --build-arg VARIANT=$VERSION .
done
4 changes: 2 additions & 2 deletions .devcontainer/create_dummyhost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ SITE=cmk

echo "Creating a dummy host via webapi.py ... "
# win10simdows
#curl -k "http://$HOST/$SITE/check_mk/webapi.py?action=add_host&_username=automation&_secret=$SECRET&request_format=python&output_format=python" -d "request={'hostname': 'win10simdows', 'folder': '', 'attributes': {'ipaddress': '192.168.116.8'}, 'create_folders': '1'}"
curl -k "http://$HOST/$SITE/check_mk/webapi.py?action=add_host&_username=automation&_secret=$SECRET&request_format=python&output_format=python" -d "request={'hostname': 'win10simdows', 'folder': '', 'attributes': {'ipaddress': '192.168.116.8'}, 'create_folders': '1'}"
# localhost
curl -k "http://$HOST/$SITE/check_mk/webapi.py?action=add_host&_username=automation&_secret=$SECRET&request_format=python&output_format=python" -d "request={'hostname': 'localhost', 'folder': '', 'attributes': {'ipaddress': '127.0.0.1'}, 'create_folders': '1'}"
# curl -k "http://$HOST/$SITE/check_mk/webapi.py?action=add_host&_username=automation&_secret=$SECRET&request_format=python&output_format=python" -d "request={'hostname': 'localhost', 'folder': '', 'attributes': {'ipaddress': '127.0.0.1'}, 'create_folders': '1'}"
echo "Discovering ... "
cmk -IIv
echo "Reloading CMK config ... "
Expand Down
15 changes: 7 additions & 8 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@
"build": {
"dockerfile": "Dockerfile",
"args": {
// "VARIANT": "2.0.0p3",
// "VARIANT": "2.0.0p4",
"VARIANT": "2.0.0p5",
"PIP": "pip3"
"VARIANT": "1.6.0p25",
"PIP": "pip"
},
},
"containerEnv": {
Expand All @@ -17,7 +15,8 @@
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
// Update any extensions in Docker, how dare you
"extensions.autoUpdate": false
"extensions.autoUpdate": false,
"python.pythonPath": "/opt/omd/sites/cmk/bin/python"
},
"extensions": [
"ms-python.python",
Expand All @@ -26,14 +25,14 @@
],
"forwardPorts": [5000],

"postCreateCommand": ".devcontainer/postCreateCommand.sh",
"postCreateCommand": "/workspaces/robotmk/.devcontainer/postCreateCommand.sh",

"remoteUser": "cmk",
"remoteEnv": {
"PATH": "/omd/sites/cmk/bin:/omd/sites/cmk/local/lib/python3/bin/:${containerEnv:PATH}",
"PATH": "/omd/sites/cmk/bin:/omd/sites/cmk/local/lib/python/bin/:${containerEnv:PATH}",
"OMD_ROOT": "/omd/sites/cmk",
"OMD_SITE": "cmk",
"CMK_SITE_ID": "cmk",
"WORKSPACE": "${containerWorkspaceFolder}"
}
},
}
4 changes: 2 additions & 2 deletions .devcontainer/devcontainer_v1.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"build": {
"dockerfile": "Dockerfile",
"args": {
"VARIANT": "1.6.0p24",
"VARIANT": "1.6.0p25",
"PIP": "pip"
},
},
Expand All @@ -16,7 +16,7 @@
"terminal.integrated.shell.linux": "/bin/bash",
// Update any extensions in Docker, how dare you
"extensions.autoUpdate": false,
"python.pythonPath": "/omd/sites/cmk/bin/python2"
"python.pythonPath": "/omd/sites/cmk/bin/python"
},
"extensions": [
"ms-python.python",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# As agent installers are only available after the first login into the site,
# we do not have access to them. Instead, a recent deb gets installed. Will work
# for most needs...
# As soon as the first installer has been baken by the bakery, the agent will
# anyhow have a version from the CMK server.

echo "Installing the Checkmk agent..."
DEB=$(realpath $(dirname $0))/cmk_agent.deb
Expand Down
9 changes: 6 additions & 3 deletions .devcontainer/postCreateCommand.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash

# This step ties the workspace files with the Devcontainer.
# V1 sites use lsyncd instead of symlinks because the bakery/rpmbuild needs real files instead of links.
.devcontainer/linkfiles.sh
# This step ties the workspace files with the Devcontainer. lsyncd is used to synchronize files.
/workspaces/robotmk/.devcontainer/linkfiles.sh

# Password for the automation user
echo "secret" > /opt/omd/sites/cmk/var/check_mk/web/automation/automation.secret

# Fire up the site
omd start
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ dist/*
mkpackage.pyc
*.mkp
*.swp
nohup.out
nohup.out
16 changes: 16 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,22 @@
// allow to inspect also foreign code
"justMyCode": false
},
{
"name": "devc V2.x bakery localhost",
"type": "python",
"request": "launch",
"program": "/omd/sites/cmk/bin/cmk",
"args": [
"-A",
"-v",
"-f",
"localhost"
],
"console": "integratedTerminal",
"python": "/omd/sites/cmk/bin/python3",
// allow to inspect also foreign code
"justMyCode": false
},
{
"name": "devc V2.x bakery win10simdows",
"type": "python",
Expand Down
10 changes: 6 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"python.pythonPath": "/omd/sites/cmk/bin/python3",
"python.pythonPath": "/omd/sites/cmk/bin/python",
"python.linting.flake8Enabled": true,
"python.linting.enabled": true,
"python.testing.pytestArgs": [
Expand All @@ -10,10 +10,12 @@
"python.testing.pytestEnabled": true,
"python.languageServer": "Pylance",
"python.autoComplete.extraPaths": [
"/omd/sites/cmk/lib/python3"
// "/omd/sites/cmk/lib/python3"
"/omd/sites/cmk/lib/python"
],
"files.eol": "\n",
"python.analysis.extraPaths": [
"/omd/sites/cmk/lib/python3"
// "/omd/sites/cmk/lib/python3"
"/omd/sites/cmk/lib/python"
]
}
}
4 changes: 4 additions & 0 deletions .vscode/tasks-chooser.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
{
"displayName": "▶︎ Set devcontainer to CMK v2",
"command": "bash .devcontainer/set_devcontainer_version.sh 2"
},
{
"displayName": "▶︎ Create dummyhost",
"command": "bash /workspaces/robotmk/.devcontainer/create_dummyhost.sh"
}
],
"baseItem": {
Expand Down
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"displayName": "▶︎ Set devcontainer to CMK v2",
"command": "cp .devcontainer/devcontainer{_v2,}.json",
"displayName": "▶︎ Create dummyhost",
"command": "bash /workspaces/robotmk/.devcontainer/create_dummyhost.sh",
"version": "2.0.0",
"type": "shell",
"problemMatcher": [],
"chooserIndex": 2
"chooserIndex": 3
}
6 changes: 3 additions & 3 deletions agents_plugins/robotmk-runner.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# (c) 2020 Simon Meggle <[email protected]>
# (c) 2021 Simon Meggle <[email protected]>

# This file is part of Robotmk, a module for the integration of Robot
# framework test results into Checkmk.
Expand All @@ -20,7 +20,7 @@

try:
# Import the main Robotmk functions from the same directory (Windows)
from robotmk import robotmk, RMKPlugin, RMKrunner, test_for_modules
from robotmk import *
except ImportError:
# If the import fails, try to import robotmk form the parent directory (Linux)
# This is the case when the runner gets scheduled asynchronously on Linux where
Expand All @@ -35,7 +35,7 @@ def main():
RMKPlugin.get_args()
rmk = RMKrunner()
cmdline_suites='all' # TBD: start suites from cmdline
rmk.start_suites(cmdline_suites)
rmk.run_suites(cmdline_suites)
rmk.loginfo("... Quitting Runner, bye. ---")
# It is important to write at least one byte to the agent so that it can save this
# as a state with a cache_time.
Expand Down
Loading

0 comments on commit 65eb3d6

Please sign in to comment.