From 7d235fb013021d771c75479450e2e2dcda1426a3 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Tue, 8 Oct 2019 18:19:20 +0200 Subject: [PATCH 1/5] add new type `__xymon_server` This type installs a Xymon monitoring-server. See https://xymon.com/ for a demo and further information. --- cdist/conf/type/__xymon_server/gencode-remote | 25 ++++++ cdist/conf/type/__xymon_server/man.rst | 87 +++++++++++++++++++ cdist/conf/type/__xymon_server/manifest | 50 +++++++++++ .../type/__xymon_server/parameter/boolean | 1 + .../__xymon_server/parameter/default/state | 1 + .../type/__xymon_server/parameter/optional | 1 + cdist/conf/type/__xymon_server/singleton | 0 7 files changed, 165 insertions(+) create mode 100755 cdist/conf/type/__xymon_server/gencode-remote create mode 100644 cdist/conf/type/__xymon_server/man.rst create mode 100755 cdist/conf/type/__xymon_server/manifest create mode 100644 cdist/conf/type/__xymon_server/parameter/boolean create mode 100644 cdist/conf/type/__xymon_server/parameter/default/state create mode 100644 cdist/conf/type/__xymon_server/parameter/optional create mode 100644 cdist/conf/type/__xymon_server/singleton diff --git a/cdist/conf/type/__xymon_server/gencode-remote b/cdist/conf/type/__xymon_server/gencode-remote new file mode 100755 index 00000000..55451c42 --- /dev/null +++ b/cdist/conf/type/__xymon_server/gencode-remote @@ -0,0 +1,25 @@ +#!/bin/sh -e +# +# 2018-2019 Thomas Eckert (tom at it-eckert.de) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +## "move" user-modified dirs to /etc/xymon to be managed by __xymon_config: +if [ ! -L /usr/lib/xymon/server/ext ]; then + echo "mv /usr/lib/xymon/server/ext /etc/xymon" + echo "ln -s /etc/xymon/ext /usr/lib/xymon/server/" + echo "ext-dir moved and symlinked" >> "$__messages_out" +fi diff --git a/cdist/conf/type/__xymon_server/man.rst b/cdist/conf/type/__xymon_server/man.rst new file mode 100644 index 00000000..a9a180e1 --- /dev/null +++ b/cdist/conf/type/__xymon_server/man.rst @@ -0,0 +1,87 @@ +cdist-type__xymon_server(7) +=========================== + +NAME +---- +cdist-type__xymon_server - Install a Xymon server + + +DESCRIPTION +----------- +This cdist type installs a Xymon (https://www.xymon.com/) server and (optional) +required helper packages. + +This includes the Xymon client as a dependency, so NO NEED to install +`__xymon_client` separately. + +To access the webinterface a webserver is required. The cdist-type +`__xymon_apache` can be used to install and configure the apache webserver for +the use with Xymon. + +Further and day-to-day configuration of Xymon can either be done manually in +`/etc/xymon/` or the directory can be deployed and managed by `__xymon_config`. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +state + 'present', 'absent', defaults to 'present'. If '--install_helpers' is + specified for 'absent' the helper packages will be un-installed. + + +BOOLEAN PARAMETERS +------------------ +install_helpers + Install helper packages used by Xymon (fping, heirloom-mailx, traceroute, + ntpdate). + + +EXAMPLES +-------- + +.. code-block:: sh + + # minmal + __xymon_server + + # the same + __xymon_server --state present + + # also install helper packages: + __xymon_server --install_helpers + + # examples to give a more complete picture: __xymon_server installed on + # `xymon.example.com` w/ IP 192.168.1.1: + # + # install webserver and grant 2 private subnets access to the webinterface: + __xymon_apache --ipacl "192.168.0.0/16 10.0.0.0/8" + # deploy server-configuration with __xymon_config: + __xymon_config --confdir=xymon.example.com + + # install xymon-client on other machines (not needed on the server): + __xymon_client --servers "192.168.1.1" + + + +SEE ALSO +-------- +:strong:`cdist__xymon_apache`\ (7), :strong:`cdist__xymon_config`\ (7), +:strong:`cdist__xymon_client`\ (7), :strong:`xymon`\ (7) + + +AUTHORS +------- +Thomas Eckert + + +COPYING +------- +Copyright \(C) 2018-2019 Thomas Eckert. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/cdist/conf/type/__xymon_server/manifest b/cdist/conf/type/__xymon_server/manifest new file mode 100755 index 00000000..7cee0d23 --- /dev/null +++ b/cdist/conf/type/__xymon_server/manifest @@ -0,0 +1,50 @@ +#!/bin/sh -e +# +# 2018-2019 Thomas Eckert (tom at it-eckert.de) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +state=$(cat "$__object/parameter/state") +if [ -f "$__object/parameter/install_helpers" ]; then + install_helpers=1 +else + install_helpers=0 +fi + +os=$(cat "$__global/explorer/os") +case "$os" in + debian|ubuntu) + : + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + ;; +esac + +__package xymon --state "$state" + +## install helper-packages/tools used by the xymon server if requested: +if [ "$install_helpers" = "1" ]; then + __package fping --state "$state" + __package heirloom-mailx --state "$state" + __package traceroute --state "$state" + __package ntpdate --state "$state" +fi + +## CLI-usage often requires a shell: +require="__package/xymon" __user xymon --shell "/bin/bash" --state "$state" diff --git a/cdist/conf/type/__xymon_server/parameter/boolean b/cdist/conf/type/__xymon_server/parameter/boolean new file mode 100644 index 00000000..56ebcb2c --- /dev/null +++ b/cdist/conf/type/__xymon_server/parameter/boolean @@ -0,0 +1 @@ +install_helpers diff --git a/cdist/conf/type/__xymon_server/parameter/default/state b/cdist/conf/type/__xymon_server/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__xymon_server/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__xymon_server/parameter/optional b/cdist/conf/type/__xymon_server/parameter/optional new file mode 100644 index 00000000..ff72b5c7 --- /dev/null +++ b/cdist/conf/type/__xymon_server/parameter/optional @@ -0,0 +1 @@ +state diff --git a/cdist/conf/type/__xymon_server/singleton b/cdist/conf/type/__xymon_server/singleton new file mode 100644 index 00000000..e69de29b From f35a1b9cdf6f91e49789f364cd5faeae01132c39 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Tue, 8 Oct 2019 18:32:26 +0200 Subject: [PATCH 2/5] add new type `__xymon_apache` as a helper for `__xymon_server` Details in `man.rst` --- .../type/__xymon_apache/explorer/active-conf | 22 ++++++ .../__xymon_apache/explorer/active-modules | 5 ++ cdist/conf/type/__xymon_apache/gencode-remote | 56 +++++++++++++ cdist/conf/type/__xymon_apache/man.rst | 79 +++++++++++++++++++ cdist/conf/type/__xymon_apache/manifest | 42 ++++++++++ .../__xymon_apache/parameter/default/state | 1 + .../type/__xymon_apache/parameter/optional | 2 + cdist/conf/type/__xymon_apache/singleton | 0 8 files changed, 207 insertions(+) create mode 100755 cdist/conf/type/__xymon_apache/explorer/active-conf create mode 100755 cdist/conf/type/__xymon_apache/explorer/active-modules create mode 100755 cdist/conf/type/__xymon_apache/gencode-remote create mode 100644 cdist/conf/type/__xymon_apache/man.rst create mode 100755 cdist/conf/type/__xymon_apache/manifest create mode 100644 cdist/conf/type/__xymon_apache/parameter/default/state create mode 100644 cdist/conf/type/__xymon_apache/parameter/optional create mode 100644 cdist/conf/type/__xymon_apache/singleton diff --git a/cdist/conf/type/__xymon_apache/explorer/active-conf b/cdist/conf/type/__xymon_apache/explorer/active-conf new file mode 100755 index 00000000..bd281e21 --- /dev/null +++ b/cdist/conf/type/__xymon_apache/explorer/active-conf @@ -0,0 +1,22 @@ +#!/bin/sh -e +# +# 2018-2019 Thomas Eckert (tom at it-eckert.de) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +if [ -d /etc/apache2/mods-enabled ]; then + ls -1 /etc/apache2/conf-enabled/ +fi diff --git a/cdist/conf/type/__xymon_apache/explorer/active-modules b/cdist/conf/type/__xymon_apache/explorer/active-modules new file mode 100755 index 00000000..4c745ced --- /dev/null +++ b/cdist/conf/type/__xymon_apache/explorer/active-modules @@ -0,0 +1,5 @@ +#!/bin/sh -e + +if [ -d /etc/apache2/mods-enabled ]; then + /usr/sbin/apachectl -t -D DUMP_MODULES | awk '/.*_module/ { gsub(/_module.*$/, ""); gsub(/^ /, ""); print }' +fi diff --git a/cdist/conf/type/__xymon_apache/gencode-remote b/cdist/conf/type/__xymon_apache/gencode-remote new file mode 100755 index 00000000..e7d8e344 --- /dev/null +++ b/cdist/conf/type/__xymon_apache/gencode-remote @@ -0,0 +1,56 @@ +#!/bin/sh -e +# +# 2018-2019 Thomas Eckert (tom at it-eckert.de) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +state=$(cat "$__object/parameter/state") + +os=$(cat "$__global/explorer/os") +case "$os" in + debian|ubuntu) + : + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + ;; +esac + +if [ "$state" = "present" ]; then + if ! grep -q ^rewrite "$__object/explorer/active-modules"; then + echo "a2enmod rewrite >/dev/null" + echo "mod:rewrite enabled" >> "$__messages_out" + fi + if ! grep -q "^cgi$" "$__object/explorer/active-modules"; then + echo "a2enmod cgi >/dev/null" + echo "mod:cgi enabled" >> "$__messages_out" + fi + + if ! grep -q ^xymon.conf "$__object/explorer/active-conf"; then + echo "a2enconf xymon >/dev/null" + echo "conf:xymon enabled" >> "$__messages_out" + fi +fi + +if grep -q "^mod:.* enabled" "$__messages_out"; then + echo "systemctl restart apache2.service" + echo "apache restarted" >> "$__messages_out" +elif grep -q "^conf:xymon enabled" "$__messages_out"; then + echo "systemctl reload apache2.service" + echo "apache reloaded" >> "$__messages_out" +fi diff --git a/cdist/conf/type/__xymon_apache/man.rst b/cdist/conf/type/__xymon_apache/man.rst new file mode 100644 index 00000000..8358c821 --- /dev/null +++ b/cdist/conf/type/__xymon_apache/man.rst @@ -0,0 +1,79 @@ +cdist-type__xymon_apache(7) +=========================== + +NAME +---- +cdist-type__xymon_apache - Configure apache2-webserver for Xymon + + +DESCRIPTION +----------- +This cdist type installs and configures apache2 to be used "exclusively" (in +the sense that no other use is taken care of) with Xymon (the systems and +network monitor). + +It depends on `__xymon_server`. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +state + 'present', 'absent', defaults to 'present'. + +ipacl + IP(-ranges) that have access to the Xymon webpages and CGIs. Apache2-style + syntax suitable for `Require ip ...`. Example: `192.168.1.0/24 10.0.0.0/8` + + +MESSAGES +-------- +mod:rewrite enabled + apache module enabled +conf:xymon enabled + apache config for xymon enabled +apache restarted + apache2.service was reloaded +apache reloaded + apache2.service was restarted + + +EXPLORERS +--------- +active-conf + lists apache2 `conf-enabled` +active-modules + lists active apache2-modules + + +EXAMPLES +-------- + +.. code-block:: sh + + # minmal, only localhost-access: + __xymon_apache + # allow more IPs to access the Xymon-webinterface: + __xymon_apache --ipacl "192.168.0.0/16 10.0.0.0/8" --state "present" + + +SEE ALSO +-------- +:strong:`cdist__xymon_server`\ (7) + + +AUTHORS +------- +Thomas Eckert + + +COPYING +------- +Copyright \(C) 2018-2019 Thomas Eckert. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/cdist/conf/type/__xymon_apache/manifest b/cdist/conf/type/__xymon_apache/manifest new file mode 100755 index 00000000..bfd0af79 --- /dev/null +++ b/cdist/conf/type/__xymon_apache/manifest @@ -0,0 +1,42 @@ +#!/bin/sh -e +# +# 2018-2019 Thomas Eckert (tom at it-eckert.de) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +state=$(cat "$__object/parameter/state") + +os=$(cat "$__global/explorer/os") +case "$os" in + debian|ubuntu) + : + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + ;; +esac + +__package apache2 --state "$state" + +## edit xymon.conf IP-ranges +if [ -f "$__object/parameter/ipacl" ]; then + require="__package/xymon" __line /etc/apache2/conf-available/xymon.conf \ + --line " Require ip $(cat "$__object/parameter/ipacl")" \ + --after "^[[:space:]]*Require local" \ + --state "present" +fi diff --git a/cdist/conf/type/__xymon_apache/parameter/default/state b/cdist/conf/type/__xymon_apache/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__xymon_apache/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__xymon_apache/parameter/optional b/cdist/conf/type/__xymon_apache/parameter/optional new file mode 100644 index 00000000..d374ec41 --- /dev/null +++ b/cdist/conf/type/__xymon_apache/parameter/optional @@ -0,0 +1,2 @@ +state +ipacl diff --git a/cdist/conf/type/__xymon_apache/singleton b/cdist/conf/type/__xymon_apache/singleton new file mode 100644 index 00000000..e69de29b From 48ed7f17541dfbdd3a1d1c17c2bbe8570f0b468f Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Tue, 8 Oct 2019 18:38:33 +0200 Subject: [PATCH 3/5] correct condition -- should check on remote side --- cdist/conf/type/__xymon_server/gencode-remote | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__xymon_server/gencode-remote b/cdist/conf/type/__xymon_server/gencode-remote index 55451c42..0770e319 100755 --- a/cdist/conf/type/__xymon_server/gencode-remote +++ b/cdist/conf/type/__xymon_server/gencode-remote @@ -18,8 +18,9 @@ # along with cdist. If not, see . ## "move" user-modified dirs to /etc/xymon to be managed by __xymon_config: -if [ ! -L /usr/lib/xymon/server/ext ]; then - echo "mv /usr/lib/xymon/server/ext /etc/xymon" - echo "ln -s /etc/xymon/ext /usr/lib/xymon/server/" - echo "ext-dir moved and symlinked" >> "$__messages_out" -fi +cat <<-EOT + if [ ! -L /usr/lib/xymon/server/ext ]; then + mv /usr/lib/xymon/server/ext /etc/xymon + ln -s /etc/xymon/ext /usr/lib/xymon/server/ + fi +EOT From e9289abfabc2ac2dfd9c3466ab1592eb7033d8e1 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Tue, 8 Oct 2019 18:55:37 +0200 Subject: [PATCH 4/5] add new type `__xymon_config` to configure xymon-servers This allows configuration of a xymon-server. The server can be installed with `__xymon_server` or manually. In the latter case the `ext/`-dir symlink has to be added. --- cdist/conf/type/__xymon_config/files/.keep | 0 cdist/conf/type/__xymon_config/gencode-remote | 23 ++++++++ cdist/conf/type/__xymon_config/man.rst | 57 +++++++++++++++++++ cdist/conf/type/__xymon_config/manifest | 24 ++++++++ .../type/__xymon_config/parameter/required | 1 + cdist/conf/type/__xymon_config/singleton | 0 6 files changed, 105 insertions(+) create mode 100644 cdist/conf/type/__xymon_config/files/.keep create mode 100644 cdist/conf/type/__xymon_config/gencode-remote create mode 100644 cdist/conf/type/__xymon_config/man.rst create mode 100644 cdist/conf/type/__xymon_config/manifest create mode 100644 cdist/conf/type/__xymon_config/parameter/required create mode 100644 cdist/conf/type/__xymon_config/singleton diff --git a/cdist/conf/type/__xymon_config/files/.keep b/cdist/conf/type/__xymon_config/files/.keep new file mode 100644 index 00000000..e69de29b diff --git a/cdist/conf/type/__xymon_config/gencode-remote b/cdist/conf/type/__xymon_config/gencode-remote new file mode 100644 index 00000000..b25a0fda --- /dev/null +++ b/cdist/conf/type/__xymon_config/gencode-remote @@ -0,0 +1,23 @@ +#!/bin/sh -e +# +# 2018-2019 Thomas Eckert (tom at it-eckert.de) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +## to speed up config-reload we send a HUP to the server process: +cat <<-EOT + pkill -HUP xymond || { echo "HUPing xymond failed" >&2; exit 1; } +EOT diff --git a/cdist/conf/type/__xymon_config/man.rst b/cdist/conf/type/__xymon_config/man.rst new file mode 100644 index 00000000..8b427ca0 --- /dev/null +++ b/cdist/conf/type/__xymon_config/man.rst @@ -0,0 +1,57 @@ +cdist-type__xymon_config(7) +=========================== + +NAME +---- +cdist-type__xymon_config - Deploy a Xymon configuration-directory + + +DESCRIPTION +----------- +This cdist type deploys a full Xymon configuration directory from the files-dir +to the host. This type requires an installed Xymon server, e.g. deployed by +`__xymon_server`. + +WARNING: This type _replaces_ the `/etc/xymon/`-directory! The previous +contents is replaced/deleted! + + +REQUIRED PARAMETERS +------------------- +confdir + The directory in `./files/` that contains the `/etc/xymon/`-content to be + deployed. + + +REQUIRED FILES +-------------- +The directory specified by `confdir` has to contain a valid xymon-configuration +(`/etc/xymon/`) _plus_ the `ext/`-directory that normally resides in +`/usr/lib/xymon/server/`. + + +EXAMPLES +-------- + +.. code-block:: sh + + __xymon_config --confdir=xymon.example.com + # this will replace /etc/xymon/ on the target host with + # the contents from __xymon_config/files/xymon.example.com/ + + +SEE ALSO +-------- +:strong:`cdist__xymon_server`\ (7), :strong:`xymon`\ (7) + +AUTHORS +------- +Thomas Eckert + + +COPYING +------- +Copyright \(C) 2018-2019 Thomas Eckert. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/cdist/conf/type/__xymon_config/manifest b/cdist/conf/type/__xymon_config/manifest new file mode 100644 index 00000000..fb1bce54 --- /dev/null +++ b/cdist/conf/type/__xymon_config/manifest @@ -0,0 +1,24 @@ +#!/bin/sh -e +# +# 2018-2019 Thomas Eckert (tom at it-eckert.de) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +confdir=$(cat "$__object/parameter/confdir") + +__rsync /etc/xymon/ \ + --source "$__type/files/$confdir/" \ + --rsync-opts "delete" diff --git a/cdist/conf/type/__xymon_config/parameter/required b/cdist/conf/type/__xymon_config/parameter/required new file mode 100644 index 00000000..43222f13 --- /dev/null +++ b/cdist/conf/type/__xymon_config/parameter/required @@ -0,0 +1 @@ +confdir diff --git a/cdist/conf/type/__xymon_config/singleton b/cdist/conf/type/__xymon_config/singleton new file mode 100644 index 00000000..e69de29b From 0bdc62482ac46d4238c4bb2389c66b40a62755c5 Mon Sep 17 00:00:00 2001 From: Thomas Eckert Date: Tue, 8 Oct 2019 19:03:38 +0200 Subject: [PATCH 5/5] add new type `__xymon_client` --- cdist/conf/type/__xymon_client/gencode-remote | 28 +++++++++ cdist/conf/type/__xymon_client/man.rst | 57 +++++++++++++++++++ cdist/conf/type/__xymon_client/manifest | 49 ++++++++++++++++ .../__xymon_client/parameter/default/servers | 1 + .../__xymon_client/parameter/default/state | 1 + .../type/__xymon_client/parameter/optional | 2 + cdist/conf/type/__xymon_client/singleton | 0 7 files changed, 138 insertions(+) create mode 100755 cdist/conf/type/__xymon_client/gencode-remote create mode 100644 cdist/conf/type/__xymon_client/man.rst create mode 100755 cdist/conf/type/__xymon_client/manifest create mode 100644 cdist/conf/type/__xymon_client/parameter/default/servers create mode 100644 cdist/conf/type/__xymon_client/parameter/default/state create mode 100644 cdist/conf/type/__xymon_client/parameter/optional create mode 100644 cdist/conf/type/__xymon_client/singleton diff --git a/cdist/conf/type/__xymon_client/gencode-remote b/cdist/conf/type/__xymon_client/gencode-remote new file mode 100755 index 00000000..49eed317 --- /dev/null +++ b/cdist/conf/type/__xymon_client/gencode-remote @@ -0,0 +1,28 @@ +#!/bin/sh -e +# +# 2018-2019 Thomas Eckert (tom at it-eckert.de) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +servers=$(cat "$__object/parameter/servers") + +if grep -q ^__key_value/CLIENTHOSTNAME "$__messages_in" || grep -q ^__key_value/XYMONSERVERS "$__messages_in" ; then + echo "systemctl restart xymon-client" + echo "restarted" >> "$__messages_out" + cat <<-EOT + echo "xymon-client xymon-client/XYMONSERVERS string $servers" | debconf-set-selections + EOT +fi diff --git a/cdist/conf/type/__xymon_client/man.rst b/cdist/conf/type/__xymon_client/man.rst new file mode 100644 index 00000000..6f90c15b --- /dev/null +++ b/cdist/conf/type/__xymon_client/man.rst @@ -0,0 +1,57 @@ +cdist-type__xymon_client(7) +=========================== + +NAME +---- +cdist-type__xymon_client - Install the Xymon client + + +DESCRIPTION +----------- +This cdist type installs the Xymon client and configures it to report with +FQDN. + + +REQUIRED PARAMETERS +------------------- +None. + + +OPTIONAL PARAMETERS +------------------- +state + 'present', 'absent', defaults to 'present'. + +servers + One or more IP adresses (space separated) of the Xymon server(s) to report + to. While DNS-names are ok it is discouraged, defaults to 127.0.0.1. + + +EXAMPLES +-------- + +.. code-block:: sh + + # minmal, report to 127.0.0.1 + __xymon_client + + # specify server: + __xymon_client --servers "192.168.1.1" + + +SEE ALSO +-------- +:strong:`cdist__xymon_server`\ (7), :strong:`xymon`\ (7) + + +AUTHORS +------- +Thomas Eckert + + +COPYING +------- +Copyright \(C) 2018-2019 Thomas Eckert. You can redistribute it +and/or modify it under the terms of the GNU General Public License as +published by the Free Software Foundation, either version 3 of the +License, or (at your option) any later version. diff --git a/cdist/conf/type/__xymon_client/manifest b/cdist/conf/type/__xymon_client/manifest new file mode 100755 index 00000000..92ad079e --- /dev/null +++ b/cdist/conf/type/__xymon_client/manifest @@ -0,0 +1,49 @@ +#!/bin/sh -e +# +# 2018-2019 Thomas Eckert (tom at it-eckert.de) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . + +state=$(cat "$__object/parameter/state") +servers=$(cat "$__object/parameter/servers") + +os=$(cat "$__global/explorer/os") +case "$os" in + debian|ubuntu) + : + ;; + *) + echo "Your operating system ($os) is currently not supported by this type (${__type##*/})." >&2 + echo "Please contribute an implementation for it if you can." >&2 + exit 1 + ;; +esac + +__package xymon-client --state "$state" + +require="__package/xymon-client" __key_value CLIENTHOSTNAME \ + --file /etc/default/xymon-client \ + --value "'$__target_hostname'" \ + --delimiter '=' \ + --state "$state" +require="__package/xymon-client" __key_value XYMONSERVERS \ + --file /etc/default/xymon-client \ + --value "'$servers'" \ + --delimiter '=' \ + --state "$state" + +## CLI-usage often requires a shell: +require="__package/xymon-client" __user xymon --shell "/bin/bash" --state "$state" diff --git a/cdist/conf/type/__xymon_client/parameter/default/servers b/cdist/conf/type/__xymon_client/parameter/default/servers new file mode 100644 index 00000000..7b9ad531 --- /dev/null +++ b/cdist/conf/type/__xymon_client/parameter/default/servers @@ -0,0 +1 @@ +127.0.0.1 diff --git a/cdist/conf/type/__xymon_client/parameter/default/state b/cdist/conf/type/__xymon_client/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__xymon_client/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__xymon_client/parameter/optional b/cdist/conf/type/__xymon_client/parameter/optional new file mode 100644 index 00000000..7c34489a --- /dev/null +++ b/cdist/conf/type/__xymon_client/parameter/optional @@ -0,0 +1,2 @@ +state +servers diff --git a/cdist/conf/type/__xymon_client/singleton b/cdist/conf/type/__xymon_client/singleton new file mode 100644 index 00000000..e69de29b