aptremotemux is inspired by hostmux.
It reads the check_mk Multisite status of the APT check and creates a tmux session with windows and panes. Then it starts a SSH session for each found due APT update and executes an update so you can monitor the update and interact if necessary. If it detects that a host is on a remote site first a SSH session to the status host is initiated and form the status host to the target host where the update is started. The target host can use the key of the status host or your personal key by agent forwading (Option: -A). Update could be fully automated (Option: -y) and the SSH session can be closed if the command was sucessfull (Option: -e).
aptremotemux relies on:
- Pthon 3
- tmux 2.3 + with earlier versions naming of panes will not work
- libtmux
- Python modules: urllib3, argparse, sys, libtmux, logging
- A custom WATO view
- A automation user called "auto" which has access to the custom WATO view
See: WATO Web-API and Multisite Automation and Web Service
Most important for automation: SSH keys have to be installed on all hosts to allow login wihtout password.
aptremotemux relies on a custom WATO view called "aptupdates" with the following properties:
Make this view available for all users
Datasource: All services
Column: Site ID
Column: Hostname
Context / Search Filters: Column: APT Updates
Service states: WARN, CRIT
Problem acknowledged: no
Service in notification period: ignore
Host/service in downtime: no
Host: UP, PENDING
Is summary host: no
aptremotemux uses a config file. The default name and location of the config file is:
/usr/local/etc/aptremotemux.conf
It contains plain Python varialbes definitions and it looks like this:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
### CONFIG
MKPROT = "https" # HTTP/HTTPS - Prorocol uesed by Multisite site
MKHOST = "nagios.server.de" # Multisite hostname
MKSITE = "SITEID" # Multisite site name
MKUSER = "auto" # WATO automation user see:
# https://mathias-kettner.de/checkmk_multisite_automation.html
MKPASS = "11122233344455566688" # WATO automation user secret
TERM = "xterm" # TERM to be used in SSH sessions
# check_mk site IDs and targets for SSH as there is no way to get a list from WATO
SITES = {
"SITEID1":"ssh.target1.host",
"SITEID2":"ssh.target2.host",
"SITEID3":"ssh.target3.host",
}
# local domains, hostnames get striped as used in WATO
LOCDOMS = [
".example.com",
]
# hosts to ignore as defined in WATO
IGNORE = [
"not.me.example.com",
]
# local sites, no SSH to status host required
LOCSITES = [
"mysitename",
]
usage: aptremotemux [-h] [-l] [-y] [-A] [-e] [-D] [-d {info,debug}] [-p PANES]
[-c CONFIG] [-C COMMAND]
Automats SSH connections in TMUX windows and panes for APT updates based on
the status of the APT check of check_mk.
optional arguments:
-h, --help show this help message and exit
-l, --list only list commands, do nothing
-y, --yes use apt with -y for automation
-A, --agent use ssh with -A for agent forwarding
-e, --exit auto exit after upgrade if exit code is zero
-D, --dryrun display every thing, do nothing
-d {info,debug}, --debug {info,debug}
enabel console logging, default is off
-p PANES, --panes PANES
maximum number of panes per window, default: 6
-c CONFIG, --config CONFIG
path to config filei, default:
/usr/local/etc/aptremotemux.conf
-C COMMAND, --command COMMAND
APT command to use, default: dist-upgrade