Skip to content
Snippets Groups Projects
Select Git revision
  • f93ecd2ca1262c91cee00eb611a9785ceb2e2d0b
  • master default protected
  • 7771-harden-postgres-backup
  • pgsql-dump-with-snapshots
  • update-colors
  • update-docs-css
  • usb-repair-stick
  • desktop-notification
  • 7000-corrections
  • db-detector
10 results

backup.sh

Blame
  • check_snmp_printer 4.03 KiB
    #!/bin/env bash
    # ============================================================
    #
    # Wrapper for check_snmp_printer plugin
    #
    # The reason behind this wrapper is detecting the snmp auth
    # parameters by check_dnmp_includes which needs a snmp target
    # to find its custom config.
    # 
    # All given params will be sent to
    # /usr/lib64/nagios/plugins/check_snmp_printer_v2.0.1
    # except "-c <script>"
    #
    # ------------------------------------------------------------
    # 2021-03-22  v0.1  <axel.hahn@iml.unibe.ch>  
    # 2023-09-18  v0.2  <axel.hahn@iml.unibe.ch>  snmpv3 support
    # 2023-10-12  v0.3  <axel.hahn@iml.unibe.ch>  parameter for custom script; detect debian
    # 2025-02-12  v1.0  <axel.hahn@unibe.ch>      add help and debug param
    # 2025-02-10  v1.1  <axel.hahn@unibe.ch>      harden sourcing files
    # ======================================================================
    
    # shellcheck source=/dev/null
    . "$( dirname "$0" )/inc_pluginfunctions" || exit 1
    . "$( dirname "$0" )/check_snmp_includes"   || exit 1
    
    self_APPVERSION=1.1
    
    debug=0
    
    # check='/usr/lib64/nagios/plugins/check_snmp_printer'
    # updated script is taken from https://github.com/Tylan/check_snmp_printer/tree/master
    nagiosDir='/usr/lib64/nagios/plugins'
    myscript="check_snmp_printer_v2.0.1"
    case "$( ph.getOS)" in
        debian)
            nagiosDir='/usr/lib/nagios/plugins'
            ;;
    esac
    
    #---------------------------------------------------
    # --- show usage
    function showHelp(){
        local _self; _self="$( basename "$0" )"
    cat <<EOH
    $( ph.showImlHelpHeader )
    
    This is a wrapper for the check_snmp_printer plugin.
    Maybe you want to upgrade it from 
    <https://github.com/Tylan/check_snmp_printer/tree/master>
    
    The wrapper does
    
    - scan for snmp auth parameters of given host by check_snmp_includes
    - adds snmp timeout
    - executes check_snmp_printer with given other params
    
    USAGE:
        $_self [-d] [-c SCRIPT] -H SNMPTARGET [other params]
    
    PARAMETERS:
    
        -d, --debug (as 1st param)
           Debug mode: shows all generated params.
           "-d" or "--debug" will be removed from params for 
           check_snmp_printer script
    
        -c SCRIPT
           Set script to execute with full path
           default: $nagiosDir/$myscript
    
        -H HOSTNAME
           required: as fqdn or ip address; default: localhost
    
        All other params for check_snmp_printer, eg.
        --consum
        --messages
        --pagecount
        --trays
    
    CONFIG FILE:
        The config file can be multiline and has the syntax
        [SNMPTARGET[,target2]]:[auth parameters]
        The auth parameters set the version and all needed values to connect.
        Snmp v2 uses a community string.
        Snmp v3 is highly recommended (you should disable Snmp v2) and needs
        a user and password.
    
    EXAMPLE:
        $_self -H 192.168.100.12 --consum
    
    EOH
    }
    
    # ------------------------------------------------------------
    # MAIN
    # ------------------------------------------------------------
    
    
    # show help
    if [ "$#" -eq 0 ]; then
        showHelp
        exit 0
    fi
    if [ "$1" = "--debug" ] || [ "$1" = "-d" ]; then
        debug=1
        shift
    fi
    
    sParams="$*"
    
    # find host behind param -H
    SNMPTARGET=$( echo $sParams | sed -Ee 's#.*\-H\ ([0-9a-z\.\-]*).*#\1#' )
    
    # detect -c <script>
    check=$(      echo $sParams | sed -Ee 's#.*\-c\ ([0-9a-z\.\-_/]*).*#\1#' )
    test "$check" = "$sParams" && check="${nagiosDir}/${myscript}"
    test "$check" = "$sParams" || sParams=$( echo $sParams | sed -Ee 's#\-c\ ([0-9a-z\.\-_/]*)##' )
    
    # find SNMPTARGET in config to add snmp auth parameters
    test -z "$SNMPAUTH" && read_config
    sParams+=" $SNMPAUTH"
    
    # find what to show ... it is more for debug message
    what=$( echo $sParams | sed -Ee 's#.*\-\-([a-z]*).*#\1#' )
    case "$what" in
        consum)
            what="Consumables"
            ;;
        messages)
            what="Messages of the printer"
            ;;
        pagecount)
            what="Number of printed pages"
            ;;
        trays)
            what="Status of trays for paper"
            sParams="$sParams --nofeeder"
            ;;
    
    esac
    
    # add our global snmp timeout
    sParams+=" -t $SNMPTIMEOUT"
    
    test "$debug" = "1" && ( echo "$what:"; echo calling $check $sParams ; echo ) 
    $check $sParams
    
    # ------------------------------------------------------------