[[linux_wiki:freeipa_report_hosts_not_responding]]

Freeipa Report Hosts Not Responding

General Information

Report registered FreeIPA client systems that don't respond to ping.

This helps to track down decommissioned systems that were not deleted from the FreeIPA servers.

Checklist


The Script

report-hosts-notresponding.sh
#!/bin/bash
# Name: report-hosts-notresponding.sh
# Description: Report Systems That Don't Respond to Ping
# Last Modified: 2018-05-31
# Recent Changes:-Initial release
###############################################################################################
 
##### Customize These Variables #####
# IPA admin user
admin_user="admin"
 
# Ping command to use (1 packet, 3 second timeout)
ping_cmd='ping -c 1 -W 3'
##### End of Customize Variables #####
 
#=====================================
# Functions; Main starts after
#=====================================
function show_usage
{
  echo -e "\n==== Report: Systems Not Responding ===="
  echo -e "\nDescription: Report systems that are not responding to ping."
  echo -e "\n--Usage--"
  echo -e "./report-hosts-notresponding.sh [OPTIONS]"
  echo -e "\n-OPTIONS-"
  echo -e "-h                    => Display usage."
  echo -e "-v                    => Verbose; extra status output."
  echo -e "\n--Other Requirements--"
  echo -e "-> FreeIPA admin access."
  echo -e
}
 
#=======================
# Get Script Arguments
#=======================
# Reset POSIX variable in case it has been used previously in this shell
OPTIND=1
 
# By default, do not output verbose
verbose_mode="no"
 
while getopts "hv" opt; do
  case "${opt}" in
    h) # -h (help) argument
      show_usage
      exit 0
    ;;
    v) # -v (verbose) argument
      verbose_mode="yes"
    ;;
    *) # invalid argument
      show_usage
      exit 0
    ;;
  esac
done
 
#===================
# Pre-checks: Make sure we have good options set
#===================
# See if we have a kerberos ticket, if not, prompt login
/usr/bin/klist -s
if [[ $? -ne 0 ]]; then
  echo ">>No kerberos ticket found for (${admin_user}), login as ${admin_user} now:"
  /usr/bin/kinit ${admin_user}
  echo
fi
 
#===================
# Main starts here
#===================
echo -e "==========================================================="
echo -e "####========= Report: Systems Not Responding ==========####"
echo -e "==========================================================="
echo
echo -e "This script will report all systems that are not responding to ping."
if [[ ${verbose_mode} == "yes" ]]; then
  echo -e "Verbose: Yes"
else
  echo -e "Verbose: No"
fi
echo -e "=>Continue?[y/n]:\c"
read run_script
 
if [[ ${run_script} != "y" ]]; then
  echo -e "\n>>Will not run the script. Exiting..."
  exit 1
fi
 
# Get all systems
echo -e ">> Getting all systems."
all_systems="$(ipa host-find --sizelimit=0 --in-hostgroups='' | grep "Host" | awk '{print $3}')"
 
# Initialize lists to nothing
systems_not_reachable=""
systems_no_dns=""
systems_other_error=""
 
echo -e ">> Pinging ($(echo ${all_systems} | wc -w)) systems\c"
if [[ ${verbose_mode} == "yes" ]]; then
  # Extra newline required if verbose messages (due to \c above)
  echo
fi
 
# Loop through all systems, create list that don't respond to ping
for system in ${all_systems}; do
 
  if [[ ${verbose_mode} == "yes" ]]; then
    echo "--> Ping system: ${system}"
  else
    # Not verbose, output a single '.' per system ping
    echo -e ".\c"
  fi
 
  ${ping_cmd} ${system} &> /dev/null
  return_code="$?"
 
  if [[ ${return_code} == "0" ]]; then
    # Got a successful reply, continue on
    if [[ ${verbose_mode} == "yes" ]]; then
      echo "---Ok"
    else
      # Do nothing ':' (equivalent to Python's 'pass')
      :
    fi
 
  elif [[ ${return_code} == "1" ]]; then
    # Host not reachable
    if [[ ${verbose_mode} == "yes" ]]; then
      echo "---Warning: Host is unreachable. (${system})"
    fi
    systems_not_reachable+="${system} "
 
  elif [[ ${return_code} == "2" ]]; then
    # Name not known
    if [[ ${verbose_mode} == "yes" ]]; then
      echo "---Warning: Name not known/no longer in DNS. (${system})"
    fi
    systems_no_dns+="${system} "
 
  else
    # Some other error occurred
    if [[ ${verbose_mode} == "yes" ]]; then
      echo "---Warning: Some other error occurred. (${system})"
    fi
    systems_other_error+="${system} "
  fi
done
 
if [[ ${verbose_mode} == "no" ]]; then
  # Extra space required if not verbose because of no newlines for '.' status output
  echo -e "[Done]"
fi
 
echo -e "\n----------------------------------------"
echo -e "---- Systems Not Responding To Ping ----"
echo -e "----------------------------------------"
 
echo -e "\n>> Hosts Unreachable (But in DNS): $(echo ${systems_not_reachable} | wc -w)"
for system in ${systems_not_reachable}; do
  echo -e "${system}"
done
 
echo -e "\n>> Hosts With Name Not Known (Not in DNS): $(echo ${systems_no_dns} | wc -w)"
for system in ${systems_no_dns}; do
  echo -e "${system}"
done
 
echo -e "\n>> Hosts with some other type of error: $(echo ${systems_other_error} | wc -w)"
for system in ${systems_other_error}; do
  echo -e "${system}"
done
 
echo -e "\n==============================================="
echo -e "=- Report: Systems Not Responding Completed. -="
echo -e "==============================================="

  • linux_wiki/freeipa_report_hosts_not_responding.txt
  • Last modified: 2019/05/26 03:50
  • (external edit)