Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(docker): add Dockerfile #52

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM alpine:3

RUN apk add --no-cache bash openjdk11-jre openssh openssl py3-pip py3-setuptools py3-wheel sshpass

# dependencies for Nagios plugin
RUN ln -s /usr/bin/python3 /usr/bin/python
RUN pip3 install unifi

COPY nagios/check_unifi /bin/check_unifi
COPY *.sh /bin

RUN chmod +x /bin/check_unifi /bin/*.sh

ENV UAP_USERNAME ubnt
ENV UAP_PASSWORD ubnt

CMD ["docker_usage.sh"]
24 changes: 24 additions & 0 deletions docker_usage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

cat <<'USAGE'
Usage:

uap_reboot.sh:

docker run --rm -it \
-e UAP_USERNAME="username" \
-e UAP_PASSWORD="password" \
-e UAP_LIST="10.0.1.10 10.0.1.20 10.0.1.30" \
unifi-linux-utils uap_reboot.sh

check_unifi:

docker run --rm -it \
unifi-linux-utils check_unifi \
-H 10.0.1.1 \
-u "username" \
-p "password"

USAGE

exit 1
30 changes: 17 additions & 13 deletions uap_reboot.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

#######################################################################
# A simple script for remotely rebooting a Ubiquiti UniFi access point
Expand All @@ -9,27 +9,31 @@
# which should be available via dnf, yum, or apt on your *nix distro.
#
# USAGE
# Update the user-configurable settings below, then run ./uap_reboot.sh from
# the command line. To reboot on a schedule, create a cronjob such as:
# 45 3 * * * /usr/local/bin/unifi-linux-utils/uap_reboot.sh > /dev/null 2>&1 #Reboot UniFi APs
# Override the user-configurable settings by providing environment variables,
# then run ./uap_reboot.sh from the command line. To reboot on a schedule,
# create a cronjob such as:
# 45 3 * * * UAP_LIST="10.0.1.10 10.0.1.20" /usr/local/bin/unifi-linux-utils/uap_reboot.sh > /dev/null 2>&1 #Reboot UniFi APs
# The above example will reboot the UniFi access point(s) every morning at 3:45 AM.
#######################################################################

# USER-CONFIGURABLE SETTINGS
username=ubnt
password=ubnt
username="${UAP_USERNAME:-ubnt}"
password="${UAP_PASSWORD:-ubnt}"
known_hosts_file=/dev/null
uap_list=( 192.168.0.2 192.168.0.3 192.168.0.4 192.168.0.5 )
IFS=' '; read -ra uap_list <<< "${UAP_LIST?}"

# SHOULDN'T NEED TO CHANGE ANYTHING PAST HERE
for i in "${uap_list[@]}"
EXIT=0
for i in "${!uap_list[@]}"
do

echo "Rebooting UniFi access point at $i..."
if sshpass -p $password ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile=$known_hosts_file $username"@$i" reboot; then
echo "Access point at $i rebooted!" 1>&2
uap_addr="${uap_list[$i]}"
echo "Rebooting UniFi access point at ${uap_addr}... ($((i + 1))/${#uap_list[@]})"
if sshpass -p "$password" ssh -oStrictHostKeyChecking=no -oUserKnownHostsFile="$known_hosts_file" "${username}@${uap_addr}" reboot; then
echo "Access point at $uap_addr rebooted!" 1>&2
else
echo "Could not reboot access point at $i." 1>&2
echo "Could not reboot access point at $uap_addr." 1>&2
EXIT=$((EXIT + 1))
fi
done
exit 0
exit $EXIT