diff --git a/checkmk/custom-files/local/monitor-os-expiry b/checkmk/custom-files/local/monitor-os-expiry new file mode 100644 index 0000000000000000000000000000000000000000..8892c86f6032127332bcf8f1eaf2b346b0b74135 --- /dev/null +++ b/checkmk/custom-files/local/monitor-os-expiry @@ -0,0 +1,52 @@ +#!/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 diff --git a/checkmk/generic/monitor-os-expiry.sls b/checkmk/generic/monitor-os-expiry.sls new file mode 100644 index 0000000000000000000000000000000000000000..ac45ca41bec7c0c4558caba747c9fb472c529723 --- /dev/null +++ b/checkmk/generic/monitor-os-expiry.sls @@ -0,0 +1,7 @@ +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