Skip to content
Snippets Groups Projects
Commit d6160dd5 authored by Jan Philipp Timme's avatar Jan Philipp Timme
Browse files

Add plugin to monitor os release expiry

parent 00e9308d
No related branches found
No related tags found
No related merge requests found
#!/bin/bash
# WARN if less than this amount of days is left on the os release
CONFIG_WARN_DAYS_LEFT=180
# CRIT if less than this amount of days is left on the os release
CONFIG_CRIT_DAYS_LEFT=90
# Fetch current time
NOW=$(date +%s)
# Fetch an easy matchable string that represents the current OS version
OS=$(lsb_release -i -r | cut -f 2 | tr '\n' ' ')
# Initialize expiredate with marker for unknown OS
expiredate=-1
# Use bash regex to match OS, assign expiredate in format of "YYYY-MM-DD"
# NOTE: You have to use [[:space:]] to match spaces because, you know, bash.
if [[ $OS =~ ^Debian[[:space:]]9 ]]; then
expiredate="2022-06-30"
elif [[ $OS =~ ^Debian[[:space:]]10 ]]; then
expiredate="2024-06-30"
elif [[ $OS =~ ^Debian[[:space:]]11 ]]; then
expiredate="2026-06-30"
elif [[ $OS =~ ^Ubuntu[[:space:]]18\.04 ]]; then
expiredate="2023-04-30"
elif [[ $OS =~ ^Ubuntu[[:space:]]20\.04 ]]; then
expiredate="2025-04-30"
elif [[ $OS =~ ^CentOS[[:space:]]7 ]]; then
expiredate="2024-06-30"
fi
# If OS is not handled yet ...
if [[ "$expiredate" == "-1" ]]; then
# ... report an error, so a dev can extend the plugin
echo "3 OS-Expiry - Unknown OS '$OS', please extend agent plugin 'monitor-os-expiry'!"
else
# otherwise, calculate remaining days for OS and report accordingly.
os_expire_timestamp=$(date -d "$expiredate" +%s)
remaining_seconds=$(($os_expire_timestamp - $NOW))
remaining_days=$(($remaining_seconds / 86400))
# Default is OK, gets overridden by WARN, then by CRIT
checkmk_status="0"
if [[ $remaining_days -le $CONFIG_WARN_DAYS_LEFT ]]; then
checkmk_status="1"
fi
if [[ $remaining_days -le $CONFIG_CRIT_DAYS_LEFT ]]; then
checkmk_status="2"
fi
echo "$checkmk_status OS-Expiry - $remaining_days days remaining for $OS)"
fi
\ No newline at end of file
hsh_checkmk_monitor_os_expiry_plugin:
file.managed:
- name: /usr/lib/check_mk_agent/local/monitor-os-expiry
- source: salt://checkmk/custom-files/local/monitor-os-expiry
- mode: 755
- user: root
- group: root
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment