Skip to content

This Icinga check establishes an SSH connection to a remote Linux host and runs whoami. It suppresses SSH errors and verifies the user is "$USERNAME." If SSH succeeds and the user is "$USERNAME" it returns 0 (OK). If either condition fails, it returns 2 (Critical).

Notifications You must be signed in to change notification settings

legna-namor/Icinga-Linux-SSH-Whoami-Check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

Explanation:

  1. Check Execution: The script tries to establish an SSH connection.
  2. The command $(...) is used to capture the output of the ssh command.
  3. 2>/dev/null is added to suppress any SSH error messages.
  4. [ $? -eq 0 ] checks if the SSH command succeeded.
  5. [ "$output" = "$USERNAME" ] compares the output of whoami to the string $USERNAME.
  6. The script exits with a status code of 0 if both conditions are true (SSH succeeded and user is $USERNAME). Otherwise, it exits with a status code of 2.

Usage in Icinga:

  • Make sure the script is executable:
chmod 755 check_ssh_whoaami.sh
chmod +x check_ssh_whoaami.sh
  • Place the script in your Icinga check command directory (/usr/lib64/nagios/plugins/).
  • Define a new check command in Icinga’s configuration:
object CheckCommand "check_ssh_whoaami" {
    command = [ "/usr/lib/nagios/plugins/check_ssh_whoaami.sh" ]
    arguments = {
        "-H" = {
            required = true
            value = "$hostname$"
        }
        "-U" = {
            required = true
            value = "$username$"
        }
    }
}
  • Use this check command in a service definition for a host.
  • Adjust the script and command definition according to your environment's needs (e.g., handling multiple arguments or specific options).

SSH KEYS

  • Place id_rsa and id_rsa at: /usr/lib64/nagios/.ssh
  • Make sure the have the correct permissions:
chmod -R 600 /usr/lib64/nagios/.ssh
chown -R icinga:icinga /usr/lib64/nagios/.ssh

About

This Icinga check establishes an SSH connection to a remote Linux host and runs whoami. It suppresses SSH errors and verifies the user is "$USERNAME." If SSH succeeds and the user is "$USERNAME" it returns 0 (OK). If either condition fails, it returns 2 (Critical).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages