Skip to content

Commit

Permalink
Merge pull request #1 from lux4rd0/v1.0.1
Browse files Browse the repository at this point in the history
V1.0.1 - Initial Release
  • Loading branch information
lux4rd0 authored Jul 19, 2021
2 parents b48b4c8 + 057e784 commit 01a78db
Show file tree
Hide file tree
Showing 31 changed files with 8,502 additions and 138 deletions.
327 changes: 326 additions & 1 deletion README.md

Large diffs are not rendered by default.

13 changes: 5 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
services:
sense-collector:
container_name: sense-collector
container_name: sense-collector-72535
environment:
SENSE_COLLECTOR_DEBUG: "false"
SENSE_COLLECTOR_DEBUG_CURL: "false"
SENSE_COLLECTOR_HEALTHCHECK: "true"
SENSE_COLLECTOR_HOST_HOSTNAME: app02.tylephony.com
SENSE_COLLECTOR_HOST_HOSTNAME: sense-collector.lux4rd0.com
SENSE_COLLECTOR_INFLUXDB_PASSWORD: none
SENSE_COLLECTOR_INFLUXDB_URL: http://influxdb01.tylephony.com:8086/write?db=sense
SENSE_COLLECTOR_INFLUXDB_URL: http://influxdb01.lux4rd0.com:8086/write?db=sense
SENSE_COLLECTOR_INFLUXDB_USERNAME: none
SENSE_COLLECTOR_MONITOR_ID: <<monitor_id>>
SENSE_COLLECTOR_TOKEN: <<token>>
SENSE_COLLECTOR_MONITOR_ID: 72535
SENSE_COLLECTOR_TOKEN: t1.1476.1474.8e6dc77daf22e1fb471d7b942w97e477d1es53bcf2d72
TZ: America/Chicago
image: lux4rd0/sense-collector:latest
restart: always
Expand Down
78 changes: 45 additions & 33 deletions generate_docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,23 @@
## Sense Collector - generate_docker-compose.sh
##

debug=$SENSE_COLLECTOR_DEBUG
debug_curl=$SENSE_COLLECTOR_DEBUG_CURL
##
## Set Specific Variables
##

collector_type="sense-collector"

influxdb_password=$SENSE_COLLECTOR_INFLUXDB_PASSWORD
influxdb_url=$SENSE_COLLECTOR_INFLUXDB_URL
influxdb_username=$SENSE_COLLECTOR_INFLUXDB_USERNAME
loki_client_url=$SENSE_COLLECTOR_LOKI_CLIENT_URL
sense_password=$SENSE_COLLECTOR_PASSWORD
sense_username=$SENSE_COLLECTOR_USERNAME


echo_bold=$(tput -T xterm bold)
echo_color_sense=$(echo -e "\e[3$(( RANDOM * 6 / 32767 + 1 ))m")
echo_color_collector=$(echo -e "\e[3$(( RANDOM * 6 / 32767 + 1 ))m")
echo_normal=$(tput -T xterm sgr0)


echo "
███████╗███████╗███╗ ██╗███████╗███████╗
Expand All @@ -38,56 +39,51 @@ echo "
"



echo "${echo_bold}Sense Collector${echo_normal} (generate_docker-compose.sh) - https://github.com/lux4rd0/sense-collector
debug=${debug}
debug_curl=${debug_curl}
influxdb_password=${influxdb_password}
influxdb_url=${influxdb_url}
influxdb_username=${influxdb_username}
loki_client_url=${loki_client_url}
sense_password=${sense_password}
sense_username=${sense_username}"
${echo_bold}influxdb_password${echo_normal}=${influxdb_password}
${echo_bold}influxdb_url${echo_normal}=${influxdb_url}
${echo_bold}influxdb_username${echo_normal}=${influxdb_username}
${echo_bold}sense_password${echo_normal}=${sense_password}
${echo_bold}sense_username${echo_normal}=${sense_username}
"

if [ -z "${influxdb_password}" ]; then echo "${echo_bold}${echo_color_sense}sense-collector:${echo_normal} ${echo_bold}SENSE_COLLECTOR_INFLUXDB_PASSWORD${echo_normal} was not set. Setting defaults: ${echo_bold}password${echo_normal}"; influxdb_password="password"; fi
if [ -z "${influxdb_password}" ]; then echo "${echo_bold}${echo_color_sense}${collector_type}:${echo_normal} ${echo_bold}SENSE_COLLECTOR_INFLUXDB_PASSWORD${echo_normal} was not set. Setting defaults: ${echo_bold}password${echo_normal}"; influxdb_password="password"; fi

if [ -z "${influxdb_url}" ]; then echo "${echo_bold}${echo_color_sense}sense-collector:${echo_normal} ${echo_bold}SENSE_COLLECTOR_INFLUXDB_URL${echo_normal} was not set. Setting defaults: ${echo_bold}http://influxdb:8086/write?db=sense${echo_normal}"; influxdb_url="http://influxdb:8086/write?db=sense" ; fi
if [ -z "${influxdb_url}" ]; then echo "${echo_bold}${echo_color_sense}${collector_type}:${echo_normal} ${echo_bold}SENSE_COLLECTOR_INFLUXDB_URL${echo_normal} was not set. Setting defaults: ${echo_bold}http://influxdb:8086/write?db=sense${echo_normal}"; influxdb_url="http://influxdb:8086/write?db=sense" ; fi

if [ -z "${influxdb_username}" ]; then echo "${echo_bold}${echo_color_sense}sense-collector:${echo_normal} ${echo_bold}SENSE_COLLECTOR_INFLUXDB_USERNAME${echo_normal} was not set. Setting defaults: ${echo_bold}influxdb${echo_normal}"; influxdb_username="influxdb"; fi
if [ -z "${influxdb_username}" ]; then echo "${echo_bold}${echo_color_sense}${collector_type}:${echo_normal} ${echo_bold}SENSE_COLLECTOR_INFLUXDB_USERNAME${echo_normal} was not set. Setting defaults: ${echo_bold}influxdb${echo_normal}"; influxdb_username="influxdb"; fi

if [ -z "${sense_password}" ]; then echo "${echo_bold}${echo_color_sense}sense-collector:${echo_normal} ${echo_bold}SENSE_COLLECTOR_PASSWORD${echo_normal} was not set. Missing Sense password. Please provide your password as an environmental variable."; fi
if [ -z "${sense_password}" ]; then echo "${echo_bold}${echo_color_sense}${collector_type}:${echo_normal} ${echo_bold}SENSE_COLLECTOR_PASSWORD${echo_normal} was not set. Missing Sense password. Please provide your password as an environmental variable."; fi

if [ -z "${sense_username}" ]; then echo "${echo_bold}${echo_color_sense}sense-collector:${echo_normal} ${echo_bold}SENSE_COLLECTOR_USERNAME${echo_normal} was not set. Missing Sense user name. Please provide your user name as an environmental variable."
if [ -z "${sense_username}" ]; then echo "${echo_bold}${echo_color_sense}${collector_type}:${echo_normal} ${echo_bold}SENSE_COLLECTOR_USERNAME${echo_normal} was not set. Missing Sense user name. Please provide your user name as an environmental variable."

else

url_sense_authenticate="https://api.sense.com/apiservice/api/v1/authenticate"

response_url_sense=$(curl -k --data "email=${sense_username}" --data "password=${sense_password}" -H "Sense-Collector-Client-Version: 1.0.0" -H "X-Sense-Protocol: 3" -H "User-Agent: okhttp/3.8.0" "${url_sense_authenticate}")
response_url_sense=$(curl --silent --show-error --fail -k --data "email=${sense_username}" --data "password=${sense_password}" -H "Sense-Collector-Client-Version: 1.0.0" -H "X-Sense-Protocol: 3" -H "User-Agent: okhttp/3.8.0" "${url_sense_authenticate}")

#echo "${response_url_sense}"

token=$(echo "${response_url_sense}" | jq -r .access_token)
monitor_id=$(echo "${response_url_sense}" | jq -r .monitors[].id)
time_zone=$(echo "${response_url_sense}" | jq -r .monitors[].time_zone)

echo "token=${token}
monitor_id=${monitor_id}
time_zone=${time_zone}"

echo "${echo_bold}token${echo_normal}=${token}
${echo_bold}monitor_id${echo_normal}=${monitor_id}
${echo_bold}time_zone${echo_normal}=${time_zone}
"

FILE_DC="${PWD}/docker-compose.yml"

if test -f "${FILE_DC}"; then
existing_file_timestamp_dc=$(date -r "${FILE_DC}" "+%Y%m%d-%H%M%S")
echo "${echo_bold}${echo_color_sense}sense-collector:${echo_normal} Existing ${echo_bold}${FILE_DC}${echo_normal} with a timestamp of ${echo_bold}${existing_file_timestamp_dc}${echo_normal} file found. Backup up file to ${FILE_DC}.${existing_file_timestamp_dc}.old"
echo "${echo_bold}${echo_color_sense}sense-collector:${echo_normal} Existing ${echo_bold}${FILE_DC}${echo_normal} with a timestamp of ${echo_bold}${existing_file_timestamp_dc}${echo_normal} file found. Backup up file to ${echo_bold}${FILE_DC}.${existing_file_timestamp_dc}.old${echo_normal}
"
mv "${FILE_DC}" "${FILE_DC}"."${existing_file_timestamp_dc}.old"
fi



##
## ┌┬┐┌─┐┌─┐┬┌─┌─┐┬─┐ ┌─┐┌─┐┌┬┐┌─┐┌─┐┌─┐┌─┐┬ ┬┌┬┐┬
## │││ ││ ├┴┐├┤ ├┬┘───│ │ ││││├─┘│ │└─┐├┤ └┬┘││││
Expand All @@ -99,9 +95,6 @@ echo "services:
container_name: sense-collector-${monitor_id}
environment:
TZ: ${time_zone}
SENSE_COLLECTOR_DEBUG: \"false\"
SENSE_COLLECTOR_DEBUG_CURL: \"false\"
SENSE_COLLECTOR_HEALTHCHECK: \"true\"
SENSE_COLLECTOR_HOST_HOSTNAME: $(hostname)
SENSE_COLLECTOR_INFLUXDB_PASSWORD: ${influxdb_password}
SENSE_COLLECTOR_INFLUXDB_URL: ${influxdb_url}
Expand All @@ -121,6 +114,25 @@ echo " SENSE_COLLECTOR_TOKEN: ${token}
restart: always
version: '3.3'" >> docker-compose.yml

echo "${echo_bold}${echo_color_sense}sense-collector:${echo_normal} ${FILE_DC} file created"
echo "${echo_bold}${echo_color_sense}sense-collector:${echo_normal} ${echo_bold}${FILE_DC}${echo_normal} file created"

fi

echo "
You may also use this docker run command:
"

echo "docker run --rm \\
--name=sense-collector-${monitor_id} \\
-e SENSE_COLLECTOR_HOST_HOSTNAME=$(hostname) \\
-e SENSE_COLLECTOR_INFLUXDB_PASSWORD=${influxdb_password} \\
-e SENSE_COLLECTOR_INFLUXDB_URL=${influxdb_url} \\
-e SENSE_COLLECTOR_INFLUXDB_USERNAME=${influxdb_username} \\
-e SENSE_COLLECTOR_MONITOR_ID=${monitor_id} \\
-e SENSE_COLLECTOR_TOKEN=${token} \\
-e TZ=America/Chicago \\
--restart always \\
lux4rd0/sense-collector:latest"



fi
1 change: 1 addition & 0 deletions grafana/shared/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Loading

0 comments on commit 01a78db

Please sign in to comment.