User Tools

Site Tools


aix:scripts_category:nagios_aix_check

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
aix:scripts_category:nagios_aix_check [2023/11/18 15:51]
manu [Check path disks]
aix:scripts_category:nagios_aix_check [2025/02/24 15:34] (current)
manu [Check path disks]
Line 321: Line 321:
 </​code>​ </​code>​
  
-==== check_ntp_aix.sh ==== +==== check_ntp_aix.sh ​(as nagios user) ==== 
  
 +<​code>​
 +#​!/​bin/​ksh93
 +#
 +# AIX check NTP for Nagios v1.0 06/2023
 +#  EIF
 +#
 +
 +STATE_OK=0
 +STATE_WARNING=1
 +STATE_CRITICAL=2
 +STATE_UNKNOWN=3
 +STATE_DEPENDENT=4
 +
 +MAXSEC=30 # max delay allowed in seconds
 +OUTPUT=$(ntpq -p 2>&1 | sed '​s/​$/;/​g'​)
 +
 +if [ $(echo $OUTPUT | grep refused >/​dev/​null 2>&​1;​ echo $?) -eq 0 ]
 +then
 +  EXIT_CODE=$STATE_CRITICAL
 +  OUTPUT="​Process:​ xntpd not running"​
 +else
 +  if [[ $(echo $OUTPUT | tr ';'​ '​\n'​ | sed '/​^$/​d'​ | sed 's/^\ //g' | tail +3) == ""​ ]]
 +  then
 +    EXIT_CODE=$STATE_CRITICAL
 +    OUTPUT="​Process:​ xntpd not running"​
 +  else
 +    OFFSET=$(echo $OUTPUT | tr ';'​ '​\n'​ | sed '/​^$/​d'​ | sed 's/^\ //g' | tail +3 | rev | awk '​{print $2}' | rev | cut -d'​.'​ -f1 | sed '​s/​+//'​ | sed '​s/​-//'​ | sort -u | tail -1)
 +    if [ $(echo $OUTPUT | tr ';'​ '​\n'​ | sed '/​^$/​d'​ | sed 's/^\ //g' | tail +3 | grep -q '​^\*';​ echo $?) -eq 0 ]
 +    then
 +      EXIT_CODE=$STATE_OK
 +      OUTPUT="​Process:​ xntpd offset ${OFFSET}s synchronized OK"
 +    else
 +      if [ $(echo $OFFSET) -lt "​$MAXSEC"​ ]
 +      then
 +        EXIT_CODE=$STATE_OK
 +        OUTPUT="​Process:​ xntpd offset ${OFFSET}s synchronized OK"
 +      else
 +        EXIT_CODE=$STATE_WARNING
 +        OUTPUT="​Process:​ xntpd offset ${OFFSET}s Not synchronized"​
 +      fi
 +    fi
 +  fi
 +fi
 +
 +echo $OUTPUT | tr ';'​ '​\n'​ | sed '/​^$/​d'​ | sed 's/^\ //g' | tail +3 | rev | awk '​{print $2}' | rev | cut -d'​.'​ -f1 | sed '​s/​-//'​
 +
 +echo $OUTPUT
 +exit $EXIT_CODE
 +</​code>​
 +
 +As root:
 <​code>​ <​code>​
 #​!/​bin/​ksh93 #​!/​bin/​ksh93
Line 519: Line 570:
 #@(#) v1.0 Count number of paths per disk #@(#) v1.0 Count number of paths per disk
 # v1.1 add sudo linux # v1.1 add sudo linux
-# v1.2 add alerting ​for sudo +# v1.2 change ​for VSCSI 
-Add these lines in sudoers files +v1.3 add verbose (-v), improvements linux 
-#[root@lnx log]# cat /​etc/​sudoers.d/​99_nagios +On linux, add into /​etc/​sudoers ​the following lines for linux: 
-#nagios ALL=(ALL) NOPASSWD: /​usr/​sbin/​multipath +     nagios ALL=(ALL) NOPASSWD: /​usr/​sbin/​multipath 
-#nrpe ALL=(ALL) NOPASSWD: /​usr/​sbin/​multipath+     nrpe ALL=(ALL) NOPASSWD: /​usr/​sbin/​multipath 
 + 
 + 
 +# number of path per type of disk 
 +pathviosfc=4 
 +pathviosscsi=2 
 +pathviossas=1 
 +pathlparfc=8 
 +pathlparscsi=2 
 +pathlparsas=1 
  
-nbpathlpar=8 
-nbpathvios=4 
-nbpath=$1 
 STATUS=0 STATUS=0
  
Line 536: Line 594:
  
 MSG=""​ MSG=""​
- +verbose=""​
-# check if server is VIOS +
-if [ -e "/​usr/​ios/​cli/​ioscli" ​+
-then +
-  nbpath1=$nbpathvios +
-else +
-  nbpath1=$nbpathlpar +
-fi+
  
 # specified value for nb paths # specified value for nb paths
 if [ "​$npath"​ == ""​ ] if [ "​$npath"​ == ""​ ]
 then then
-  nbpath=$nbpath1+  nbpath=$pathlparfc
 fi fi
  
Line 558: Line 609:
 count_linux_path() count_linux_path()
 { {
 +tempfile=/​tmp/​multipath.txt
 +
 if [ ! -x /​usr/​sbin/​multipath ] || [ $(lsscsi -s | grep -q VMware; echo $?) -eq 0 ] if [ ! -x /​usr/​sbin/​multipath ] || [ $(lsscsi -s | grep -q VMware; echo $?) -eq 0 ]
 then then
   MSG="​OK:​ no multipathing"​   MSG="​OK:​ no multipathing"​
 +  verbose="​$MSG"​
   STATUS=$STATE_OK   STATUS=$STATE_OK
 else else
-  if [ $(timeout ​10  sudo /​usr/​sbin/​multipath ; echo $?) -ne "​0"​ ]+  if [ $(timeout ​30  sudo /​usr/​sbin/​multipath ​-ll | grep -v "​policy="​ | grep -v "​size="​ | tr -s ' ' | sed 's/\ /;/g' | sed '/​^mpath/​i \\n' > $tempfile ​; echo $?) -ne "​0"​ ]
   then   then
     MSG="​$MSG Maybe error on sudo config"​     MSG="​$MSG Maybe error on sudo config"​
 +    verbose="​$MSG"​
     STATUS=$STATE_UNKNOWN     STATUS=$STATE_UNKNOWN
   else   else
-    for i in $(sudo /​usr/​sbin/​multipath -ll | grep mpath | awk '​{print $1}')+    for i in $(cat $tempfile ​| grep '^mpath' ​| awk -F';' ​'​{print $1}')
     do     do
-      pathok=$(sudo /​usr/​sbin/​multipath -ll $i | grep -v "​policy="​ | grep -v "​size="​ | grep -v '​^mpath'​ | grep active | wc -l | awk '​{print $1}')+      pathok=$(cat $tempfile | grepp "^$i;" ​| grep -v "​policy="​ | grep -v "​size="​ | grep -v '​^mpath'​ | grep active | wc -l | awk '​{print $1}')
       pathok_pct=$(echo "​scale=1;​100*$pathok/​$nbpath"​ | bc | cut -d '​.'​ -f1)       pathok_pct=$(echo "​scale=1;​100*$pathok/​$nbpath"​ | bc | cut -d '​.'​ -f1)
-      if [ "​$pathok_pct"​ -le "​50"​ ]+      ​verbose="​$verbose $i;​$pathok/​$nbpath"​ # verbose message 
 +      ​if [ "​$pathok_pct"​ -lt "​50"​ ]
       then       then
         MSG="​$MSG $i;​$pathok/​$nbpath"​         MSG="​$MSG $i;​$pathok/​$nbpath"​
Line 592: Line 648:
   fi   fi
 fi fi
 +
 +rm -f $tempfile 2>/​dev/​null
 } }
  
Line 597: Line 655:
 count_aix_path() count_aix_path()
 { {
-if [ $(lsdev -Cc disk | grep -v Available | wc -l | awk '​{print $1}') -ne "​0"​ ]+# check not available disks 
 +nbdisknok=$(lsdev -Cc disk | grep -v Available | wc -l | awk '​{print $1}') 
 +if [ "​$nbdisknok" ​-ne "​0"​ ]
 then then
-  MSG="​$MSG WARNING: disks defined"​+  MSG="​$MSG WARNING: ​$nbdisknok ​disks defined
 +  verbose="​$MSG"
   STATUS=$STATE_WARNING   STATUS=$STATE_WARNING
 else else
Line 605: Line 666:
 fi fi
  
-for in $(lsdev -Cc disk | grep -i mpio awk '{print $1}')+for line in $(lsdev -Cc disk | tr -s ' ' ​sed 's/\ /:/' | sed 's/\ /:/' | sed 's/\ /,/g')
 do do
-  pathok=$(lspath -l $| grep Enabled | wc -l | awk '​{print $1}')+  ​hdisk=$(echo $line | awk -F':'​ '​{print $1}'​) 
 +  if [ "​$(echo $line | cut -d':'​ -f3- | tr '​A-Z'​ '​a-z'​ | grep -q mpio; echo $?)" -eq "​0"​ ] 
 +  then 
 +    if [ ! -e /​usr/​ios/​cli/​ioscli ] 
 +        then 
 +          # type LPAR FC 
 +          nbpath=$pathlparfc 
 +    else 
 +          # type VIOS FC 
 +          nbpath=$pathviosfc 
 +    fi 
 +  else 
 +    if [ "​$(echo $line | cut -d':'​ -f3- | tr '​A-Z'​ '​a-z'​ | grep -q scsi; echo $?)" -eq "​0"​ ] 
 +    then 
 +      if [ ! -e /​usr/​ios/​cli/​ioscli ] 
 +          then 
 +            # type LPAR SCSI 
 +            nbpath=$pathlparscsi 
 +      else 
 +            # type VIOS SCSI 
 +            nbpath=$pathviosscsi 
 +      fi 
 +    else 
 +      if [ "​$(echo $line | cut -d':'​ -f3- | tr '​A-Z'​ '​a-z'​ | grep -q sas; echo $?)" -eq "​0"​ ] 
 +      then 
 +        if [ ! -e /​usr/​ios/​cli/​ioscli ] 
 +            then 
 +              # type LPAR SAS 
 +              nbpath=$pathlparsas 
 +        else 
 +              # type VIOS SAS 
 +              nbpath=$pathviossas 
 +        fi 
 +          fi 
 +        fi 
 +  fi 
 + 
 +  ​pathok=$(lspath -l $hdisk | grep Enabled | wc -l | awk '​{print $1}')
   pathok_pct=$(echo "​scale=1;​100*$pathok/​$nbpath"​ | bc | cut -d '​.'​ -f1)   pathok_pct=$(echo "​scale=1;​100*$pathok/​$nbpath"​ | bc | cut -d '​.'​ -f1)
-  if [ "​$pathok_pct"​ -le "​50"​ ]+  ​verbose="​$verbose $hdisk;​$pathok/​$nbpath"​ 
 +  ​if [ "​$pathok_pct"​ -lt "​50"​ ]
   then   then
-    MSG="​$MSG $i;​$pathok/​$nbpath"​+    MSG="​$MSG $hdisk;​$pathok/​$nbpath"​
     if [ $STATUS -lt $STATE_CRITICAL ]     if [ $STATUS -lt $STATE_CRITICAL ]
     then     then
Line 619: Line 718:
     if [ "​$pathok_pct"​ -ne "​100"​ ]     if [ "​$pathok_pct"​ -ne "​100"​ ]
     then     then
-      MSG="​$MSG $i;​$pathok/​$nbpath"​+      MSG="​$MSG $hdisk;​$pathok/​$nbpath"​
       if [ $STATUS -lt $STATE_CRITICAL ]       if [ $STATUS -lt $STATE_CRITICAL ]
       then       then
Line 629: Line 728:
 } }
  
 +######################​
 if [ "​$os"​ = "​Linux"​ ] if [ "​$os"​ = "​Linux"​ ]
 then then
Line 648: Line 747:
 else else
   echo "​$MSG"​   echo "​$MSG"​
 +fi
 +
 +# For debug
 +if [ "​$1"​ = "​-v"​ ]
 +then
 +  echo "​$verbose"​ | tr ' ' '​\n'​
 fi fi
  
 exit $STATUS exit $STATUS
 </​code>​ </​code>​
 +
  
 ==== Check SEA status ==== ==== Check SEA status ====
Line 662: Line 768:
 <​code>​ <​code>​
 #!/bin/ksh #!/bin/ksh
 +# v1.1 eif check LACP
 +#
 +# Add sudoers:
 +#nagios ALL=(ALL) NOPASSWD: /​usr/​bin/​entstat
 +#nrpe ALL=(ALL) NOPASSWD: /​usr/​bin/​entstat
 +
  
 #valeurs retour Nagios #valeurs retour Nagios
Line 674: Line 786:
 hostname=$(hostname) hostname=$(hostname)
 SEA=$(lsdev -Cc adapter | grep Shared|grep -v Defined | wc -l | awk '​{print $1}') SEA=$(lsdev -Cc adapter | grep Shared|grep -v Defined | wc -l | awk '​{print $1}')
-now=$(date +"​%d_%m_%Y_%H%M%S"​) 
-#echo $now 
  
 #​Initialisation #​Initialisation
-echo ""​ > verif_eth_$now.txt 
- 
-#​Verification Carte 
-#echo $SEA 
 if [ $SEA = "​0"​ ] if [ $SEA = "​0"​ ]
 then then
-        #echo ""​ +  MSG="No SEA available on $hostname"​ 
-        echo "No SEA available on $hostname"​ +  ​EXITSTATUS=2 ​#Exit status critical 
-        #echo ""​ +else 
-        EXITSTATUS=2 #Exit status ​critical +  #​Verification ensemble des cartes si disponible 
-        #echo $EXITSTATUS +  for ent in $(lsdev -Cc adapter | grep Shared | awk '​{print $1}'​) 
-        ​exit ​$EXITSTATUS+  do 
 +    # check physical ports / links 
 +    count_all=$(sudo /​usr/​bin/​entstat -d $ent 2>&1 | grep -i status | grep "Physical Port Link Status"​ | wc -l | awk '​{print $1}'​) 
 +    count_up=$(sudo /​usr/​bin/​entstat -d $ent 2>&1 | grep -i status | grep "​Physical Port Link Status"​ | grep Up |wc -l | awk '​{print $1}'​) 
 + 
 +    if [ $count_up -ne $count_all ] 
 +    then 
 +      MSG="​One or more Ethernet port down
 +      EXITSTATUS=1 #Exit status Warning 
 +    else 
 +      MSG="​No ethernet port issue"​ 
 +      EXITSTATUS=0 #Exit status OK 
 +    fi 
 + 
 +    # check physical ports Speed, must be the same on all ports 
 +    nb_speed=$(sudo /​usr/​bin/​entstat -d $ent 2>&1 | grep "​Physical Port Speed" | sort -u | wc -l | awk '​{print $1}'​) 
 + 
 +    if [ $nb_speed != "​1"​ ] 
 +    then 
 +      MSG="​Ethernet Ports bad speed"​ 
 +      EXITSTATUS=1 ​#Exit status ​Warning 
 +    fi 
 + 
 +    ​check LACP 
 +    count_all=$(sudo /​usr/​bin/​entstat -d $ent 2>&1 | grep "​Synchronization"​ | wc -l | awk '​{print $1}'​) 
 +    count_up=$(sudo /​usr/​bin/​entstat -d $ent 2>&1 | grep "​Synchronization"​ | grep '​IN_SYNC'​ | wc -l | awk '​{print $1}'​) 
 +    ​echo "​count_all=$count_all count_up=$count_up"​ >> /tmp/aaa 
 +    if [ $count_up -ne $count_all ] 
 +    then 
 +      MSG="​LACP not synced"​ 
 +      ​EXITSTATUS=1 #Exit status Warning 
 +    fi 
 +  done
 fi fi
  
-#​Verification ensemble des cartes si disponible +echo $MSG
-for ent in $(lsdev -Cc adapter | grep Shared | awk '​{print $1}'​) +
-do +
-        entstat -d $ent 2>&1 | grep -i status| grep "​Physical Port Link Status"​ > verif_eth_$now.txt +
-        count_all=$(cat verif_eth_$now.txt |wc -l| awk '​{print $1}'​) +
-        count_up=$(cat verif_eth_$now.txt |grep Up |wc -l| awk '​{print $1}'​) +
-        #echo $count_up +
-        #echo $count_all +
-        if [ $count_up -ne $count_all ] +
-        then +
-                echo "One or more Ethernet port down"​ +
-                #cat verif_eth_$now.txt +
-                EXITSTATUS=1 #Exit status Warning +
-                #echo $EXITSTATUS +
-        else +
-                echo "No ethernet port issue"​ +
-                #cat verif_eth_$now.txt +
-                EXITSTATUS=0 #Exit status OK +
-                #echo $EXITSTATUS +
-        fi +
-done +
-rm verif_eth_$now.txt+
 exit $EXITSTATUS exit $EXITSTATUS
 </​code>​ </​code>​
 +
 +
aix/scripts_category/nagios_aix_check.1700319092.txt.gz · Last modified: 2023/11/18 15:51 by manu