Last active
          September 18, 2024 14:59 
        
      - 
      
 - 
        
Save jazzl0ver/0d69d487d6c3deab5cebcb1595acb02c to your computer and use it in GitHub Desktop.  
    Nagios check for systemd failed units 
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #!/bin/bash | |
| # Source http://lzone.de/blog/Nagios+Check+for+Systemd+Failed+Units | |
| # Nagios return codes | |
| STATE_OK=0 | |
| STATE_WARNING=1 | |
| STATE_CRITICAL=2 | |
| STATE_UNKNOWN=3 | |
| if [ -f /bin/systemctl ]; then | |
| failed=$(/bin/systemctl --failed --no-legend | grep -v masked) | |
| failed=${failed/ */} # Strip everything after first space | |
| failed=${failed/.service/} # Strip .service suffix | |
| if [ "$failed" != "" ]; then | |
| echo "CRITICAL: Failed units - $failed" | |
| exit $STATE_CRITICAL | |
| else | |
| echo "OK: No failed units" | |
| exit $STATE_OK | |
| fi | |
| else | |
| echo "UNKNOWN: No systemd. Nothing was checked" | |
| exit $STATE_UNKNOWN | |
| fi | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment