adding node exporter, loki, and promtail
This commit is contained in:
		@@ -0,0 +1,82 @@
 | 
			
		||||
#!/usr/bin/env bashio
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Home Assistant Community Add-on: Prometheus Node Exporter
 | 
			
		||||
# Configures Prometheus Node Exporter
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
bashio::require.unprotected
 | 
			
		||||
echo "${SUPERVISOR_TOKEN}" > '/run/home-assistant.token'
 | 
			
		||||
 | 
			
		||||
# Even if the user isn't using these options, we're creating the web config file
 | 
			
		||||
# This will allow us to append to the web config file as needed (based on variables)
 | 
			
		||||
# Prometheus Node Exporter will run with a blank web config file in the meantime
 | 
			
		||||
 | 
			
		||||
config_dir=/config
 | 
			
		||||
web_config_dir=$config_dir/prometheus_node_exporter
 | 
			
		||||
mkdir -p $web_config_dir
 | 
			
		||||
chmod 750 $web_config_dir
 | 
			
		||||
chown root:prometheus $web_config_dir
 | 
			
		||||
 | 
			
		||||
web_config_file=$web_config_dir/node_exporter_web.yml
 | 
			
		||||
rm -f $web_config_file
 | 
			
		||||
touch $web_config_file
 | 
			
		||||
chmod 740 $web_config_file
 | 
			
		||||
chown root:prometheus $web_config_file
 | 
			
		||||
 | 
			
		||||
# Poor man's debugger: check permissions on web config file
 | 
			
		||||
#ls -la $web_config_file
 | 
			
		||||
 | 
			
		||||
bashio::log.info "Add-on info - name:     $(bashio::addon.name)"
 | 
			
		||||
bashio::log.info "Add-on info - version:  $(bashio::addon.version)"
 | 
			
		||||
bashio::log.info "Add-on info - hostname: $(bashio::addon.hostname)"
 | 
			
		||||
bashio::log.info "Add-on info - DNS name: $(bashio::addon.dns)"
 | 
			
		||||
bashio::log.info "Checking configuration options..."
 | 
			
		||||
 | 
			
		||||
#####################
 | 
			
		||||
# HTTP Basic Auth
 | 
			
		||||
#####################
 | 
			
		||||
 | 
			
		||||
if bashio::config.false 'enable_basic_auth'; then
 | 
			
		||||
  bashio::log.warning "HTTP Basic Auth is disabled!"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if bashio::config.true 'enable_basic_auth'; then
 | 
			
		||||
  bashio::log.info "HTTP Basic Auth is enabled!"
 | 
			
		||||
 | 
			
		||||
  # Require variables
 | 
			
		||||
  bashio::config.require 'basic_auth_user' "You enabled HTTP Basic Auth, so you must set a username"
 | 
			
		||||
  bashio::config.require 'basic_auth_pass' "You enabled HTTP Basic Auth, so you must set a password"
 | 
			
		||||
  basic_auth_user="$(bashio::config 'basic_auth_user')"
 | 
			
		||||
  basic_auth_pass="$(bashio::config 'basic_auth_pass')"
 | 
			
		||||
 | 
			
		||||
  # bcrypt the password
 | 
			
		||||
  hashed_password=$(htpasswd -bnBC 12 "" "$basic_auth_pass" | tr -d ':\n')
 | 
			
		||||
 | 
			
		||||
  # Start echoing lines out to web config file (YAML is space-sensitive so I'm lazily not using a heredoc)
 | 
			
		||||
  echo "basic_auth_users:" >> $web_config_file
 | 
			
		||||
  echo "    $basic_auth_user: $hashed_password" >> $web_config_file
 | 
			
		||||
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
#####################
 | 
			
		||||
# TLS
 | 
			
		||||
#####################
 | 
			
		||||
 | 
			
		||||
if bashio::config.false 'enable_tls'; then
 | 
			
		||||
  bashio::log.warning "TLS is disabled!"
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if bashio::config.true 'enable_tls'; then
 | 
			
		||||
  bashio::log.info "TLS is enabled!"
 | 
			
		||||
 | 
			
		||||
  # Require variables
 | 
			
		||||
  bashio::config.require 'cert_file' "You enabled TLS, so you must set certificate file"
 | 
			
		||||
  bashio::config.require 'cert_key' "You enabled TLS, so you must set certificate key"
 | 
			
		||||
  cert_file="$(bashio::config 'cert_file')"
 | 
			
		||||
  cert_key="$(bashio::config 'cert_key')"
 | 
			
		||||
 | 
			
		||||
  # Start echoing lines out to web config file (YAML is space-sensitive so I'm lazily not using a heredoc)
 | 
			
		||||
  echo "tls_server_config:" >> $web_config_file
 | 
			
		||||
  echo "    cert_file: $cert_file" >> $web_config_file
 | 
			
		||||
  echo "    key_file: $cert_key" >> $web_config_file
 | 
			
		||||
 | 
			
		||||
fi
 | 
			
		||||
@@ -0,0 +1,9 @@
 | 
			
		||||
#!/usr/bin/env bashio
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Home Assistant Community Add-on: Prometheus Node Exporter
 | 
			
		||||
# Runs the Prometheus Node Exporter
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
bashio::log.info "Starting Prometheus Node Exporter..."
 | 
			
		||||
 | 
			
		||||
# Run Prometheus
 | 
			
		||||
exec /usr/local/bin/node_exporter --web.config.file=/config/prometheus_node_exporter/node_exporter_web.yml $(bashio::config 'cmdline_extra_args' '')
 | 
			
		||||
							
								
								
									
										16
									
								
								prometheus_node_exporter/rootfs/run.sh
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								prometheus_node_exporter/rootfs/run.sh
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
#!/usr/bin/env bashio
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
# Home Assistant Community Add-on: Prometheus Node Exporter
 | 
			
		||||
# Runs the Prometheus Node Exporter
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
#
 | 
			
		||||
# WHAT IS THIS FILE?!
 | 
			
		||||
#
 | 
			
		||||
# The Prometheus Node Exporter add-on runs in the host PID namespace, therefore it cannot
 | 
			
		||||
# use the regular S6-Overlay; hence this add-on uses a "old school" script
 | 
			
		||||
# to run; with a couple of "hacks" to make it work.
 | 
			
		||||
# ==============================================================================
 | 
			
		||||
/etc/cont-init.d/node_exporter.sh
 | 
			
		||||
 | 
			
		||||
# Start Prometheus Node Exporter
 | 
			
		||||
exec /etc/services.d/node_exporter/run
 | 
			
		||||
		Reference in New Issue
	
	Block a user