Showing posts with label Zabbix. Show all posts
Showing posts with label Zabbix. Show all posts

2015/04/20

Get SSL Certificate Vitals in Linux



This script will let you programmatically get a certificate start date, number of days remaining, and certificate hash, suitable for example for automated checking for expired or changed certificates, as with Zabbix:


#!/bin/bash

function printHelpTextd
{
        echo
        echo "######################################################################"
        echo "#                                                                    #"
        echo "#  This script takes these parameters, in this order:                #"
        echo "#  1. check type, one of: certstartdate, certdaysleft, or certhash.  #"
        echo "#  2. Host connection target (IP address or host name (fqdn)).       #"
        echo "#  3. TCP port number to connect to.                                 #"
        echo "#                                                                    #"
        echo "#  This script returns, depending on the check type, one of:         #"
        echo "#  - certstartdate: a text string of the cert start date             #"
        echo "#  - certdaysleft: an integer of the number of days until the cert   #"
        echo "#    expiration; if the cert has expired, then a negative number.    #"
        echo "#  - certhash: a hash of the cert, useful for detecting changes.     #"
        echo "#                                                                    #"
        echo "######################################################################"
        echo
}


ERR_BADNUMPARAMS=1
ERR_BADCHECKTYPE=2

#  Function getCertStartDate
#  parameters (ordered)
#    * Host connection target (IP address or host name (fqdn)).
#    * TCP port number to connect to.
#  returns a text string of the certificate start date.
function getCertStartDate
{
        host=$1
        port=$2
        startdate=`echo quit | openssl s_client -host $host -port $port 2>/dev/null | awk '/BEGIN/{s=x}{s=s$0"\n"}/END CERTIFICATE-----/{print s}' 2>/dev/null | openssl x509 -noout -dates 2>/dev/null | head -n 1 | cut -d "=" -f 2- | awk -F " " '{ print $1" "$2" "$4" "$3" "$5 }'`
        echo $startdate
}


#  Function getCertDaysLeft
#  parameters (ordered)
#    * Host connection target (IP address or host name (fqdn)).
#    * TCP port number to connect to.
#  returns a number of days remaining
function getCertDaysLeft
{
        host=$1
        port=$2
        enddate=`echo quit | openssl s_client -host $host -port $port 2>/dev/null | awk '/BEGIN/{s=x}{s=s$0"\n"}/END CERTIFICATE-----/{print s}' | openssl x509 -noout -dates 2>/dev/null | tail -n 1 | cut -d "=" -f 2-`
        formattedenddate=`echo $enddate | awk -F " " '{ print $1" "$2" "$4" "$3" "$5 }'`
        enddateseconds=`date -d "$formattedenddate" +%s`
        # expiration date minus todays date = the number of days left (in seconds)
        secondsleft=$(expr $enddateseconds - $(date +%s))
        daysleft=$(expr $secondsleft / 86400)
        echo $daysleft
}


#  Function getCertHash
#  parameters (ordered)
#    * Host connection target (IP address or host name (fqdn)).
#    * TCP port number to connect to.
#  returns the hash of the cert, as a string
function getCertHash
{
        host=$1
        port=$2
        hash=`echo quit | openssl s_client -host $host -port $port 2>/dev/null | awk '/BEGIN/{s=x}{s=s$0"\n"}/END CERTIFICATE-----/{print s}' | openssl x509 -noout -hash 2>/dev/null`
        echo $hash
}


if [ "$#" -ne 3 ]; then
{
        echo "ERROR: Illegal number of parameters."
        printHelpText
        exit $ERR_BADNUMPARAMS
}; else
{
        Operation=$1
        TargetHost=$2
        TargetPort=$3
        case $Operation in
        certstartdate)
                getCertStartDate $TargetHost $TargetPort
                ;;
        certdaysleft)
                getCertDaysLeft $TargetHost $TargetPort
                ;;
        certhash)
                getCertHash $TargetHost $TargetPort
                ;;
        *)
                {
                        echo "ERROR: Bad check type."
                        printHelpText
                        exit $ERR_BADCHECKTYPE
                }
                ;;
        esac
}; fi


2014/08/28

Authentification is not a word

Whether one is referring to...

authentication - the validation of credentials (i.e., "Yes, you are who you claim to be")
authorization - the validation of whether access should be granted based on that identity (based on role, group membership, policy, ACL, etc.) (i.e., "Yes, that user is allowed to access that resource")

...the word "authentiFIcation" never comes into play... nor authentify, authentificated, etc.

Identification / identify is a valid word, mind you.

Just saying...

2013/03/15

SNMP OIDs for temperature monitoring

...This is for anyone looking for these things in one place, with the scale and units. ( extracted from http://wleibzon.bol.ucla.edu/nagios/plugins/check_snmp_temperature.pl )
  • Dell (10C)
    • 1.3.6.1.4.1.674.10892.1.700.20.1.8
    • 1.3.6.1.4.1.674.10892.1.700.20.1.6
  • Cisco (C)
    • 1.3.6.1.4.1.9.9.13.1.3.1.2
    • 1.3.6.1.4.1.9.9.13.1.3.1.3
    • fans: 1.3.6.1.4.1.9.9.13.1.4.1.3
  •  juniper (C)
    • 1.3.6.1.4.1.2636.3.1.13.1.5
    • 1.3.6.1.4.1.2636.3.1.13.1.7
  • HP (C)
    • 1.3.6.1.4.1.232.6.2.6.8.1.3
    • 1.3.6.1.4.1.232.6.2.6.8.1.4
  • alteon (C)
    • Rear Left Sensor - 1.3.6.1.4.1.1872.2.1.1.6.0
    • Rear Middle Sensor - 1.3.6.1.4.1.1872.2.1.1.7.0
    • Front Middle Sensor - 1.3.6.1.4.1.1872.2.1.1.8.0
    • Front Right Sensor - 1.3.6.1.4.1.1872.2.1.1.9.0
  • baytech PDU (10C)
    • 1.3.6.1.4.1.4779.1.3.5.2.1.2
    • 1.3.6.1.4.1.4779.1.3.5.2.1.8
  • Linux lmsensors (1000C)
    • 1.3.6.1.4.1.2021.13.16.2.1.2
    • 1.3.6.1.4.1.2021.13.16.2.1.3
  • APC temperature
    • 1.3.6.1.4.1.318.1.1.2.1.1.0
  • APC humidity 
    • 1.3.6.1.4.1.318.1.1.2.1.2.0
  • HP switch
    • temperature: 1.3.6.1.4.1.11.2.14.11.1.2.6.1.4.4
    • fan: 1.3.6.1.4.1.11.2.14.11.1.2.6