Skip to content

Instantly share code, notes, and snippets.

@maxried
Created September 15, 2016 12:59

Revisions

  1. maxried revised this gist Sep 15, 2016. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion check_snmp_perf.bash
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    #!/bin/bash
    #!/usr/bin/env bash

    oid=""
    community=""
  2. maxried created this gist Sep 15, 2016.
    51 changes: 51 additions & 0 deletions check_snmp_perf.bash
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #!/bin/bash

    oid=""
    community=""
    host=""
    label=""
    unit=""

    while getopts "C:H:o:l:u:" o; do
    case "${o}" in
    C)
    community="$OPTARG"
    ;;
    H)
    host="$OPTARG"
    ;;
    o)
    oid="$OPTARG"
    ;;
    l)
    label="$OPTARG"
    ;;
    u)
    unit="$OPTARG"
    ;;
    esac
    done

    result=$(snmpget -v2c -c $community -Oq -mALL "$host" "$oid" 2> /dev/null)

    if [[ $? != 0 ]]; then
    echo "SNMP UNKNOWN - $?"
    exit 3
    else
    declare -a 'a=('"$result"')'


    name=${a[0]}
    value=${a[1]}
    unitsnmp=${a[2]}

    if [[ "$label" != "" ]]; then
    name="$label"
    fi

    if [[ "$unit" != "" ]]; then
    unitsnmp="$unit"
    fi
    fi

    echo "SNMP OK - $name $value $unitsnmp | '$name'=$value"