The smallest watchdog on earth. Tiny, monitoring-plugins compatible monitoring with a status page. https://cloud.docker.com/repository/docker/momar/chihuahua/general
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.3KB

  1. package chihuahua
  2. import "strings"
  3. func SetupScript(keys string) string {
  4. return `#!/bin/sh
  5. set -eu
  6. # Install basic monitoring-plugins
  7. apt-get install -y monitoring-plugins
  8. # Create user "chihuahua" and add authorized SSH keys
  9. useradd -M -d /var/chihuahua -r -s /bin/sh chihuahua || true
  10. mkdir -p /var/chihuahua/.ssh
  11. echo 'export PATH="/var/chihuahua/:/usr/lib/nagios/plugins/:/usr/local/bin:/usr/bin:/bin"' > /var/chihuahua/.chihuahuarc
  12. cat <<'EOF' > /var/chihuahua/.ssh/authorized_keys
  13. ` + strings.TrimSpace(keys) + `
  14. EOF
  15. # Add "check_sudo" script to securely run checks as root
  16. cat <<'EOF' > /usr/local/bin/check_sudo
  17. #!/bin/sh
  18. [ $# -gt 0 ] || { echo "Usage: sudo /usr/local/bin/check_sudo check_... ..."; exit 3; }
  19. cmd=$(realpath --canonicalize-existing --no-symlinks "/usr/lib/nagios/plugins/$1" | grep --max-count 1 '^/usr/lib/nagios/plugins/check_') || { echo "Not a nagios plugin."; exit 3; }
  20. shift
  21. exec "$cmd" "$@"
  22. EOF
  23. cat <<'EOF' > /var/chihuahua/check_sudo
  24. #!/bin/sh
  25. sudo /usr/local/bin/check_sudo "$@"
  26. EOF
  27. chmod +x /usr/local/bin/check_sudo /var/chihuahua/check_sudo
  28. grep chihuahua /etc/sudoers >/dev/null || { echo 'chihuahua ALL=(root) NOPASSWD: /usr/local/bin/check_sudo' >> /etc/sudoers; }
  29. chown -R chihuahua:chihuahua /var/chihuahua
  30. echo Setup complete.
  31. `
  32. }