This commit is contained in:
alban 2022-06-02 23:24:09 +02:00
parent e5d4265dbe
commit 0b26e87b3c

View File

@ -1,6 +1,14 @@
#! /bin/bash #! /bin/bash
# sudo apt update
# @todo check for root
# @todo check distrib / version
# @todo ask IP address
## HOMEASSISTANT INSTALL
sudo apt update
sudo apt install git vim python3 python3-pip chromium-browser sudo apt install git vim python3 python3-pip chromium-browser
sudo apt-get install -y python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0-dev tzdata sudo apt-get install -y python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0-dev tzdata
sudo useradd -rm homeassistant sudo useradd -rm homeassistant
@ -31,47 +39,146 @@ RestartForceExitStatus=100
WantedBy=multi-user.target WantedBy=multi-user.target
EOF EOF
cat <<EOF | sudo -u homeassistant tee /home/homeassistant/.homeassistant/configuration.yaml
# File: /home/homeassistant/.homeassistant/configuration.yaml
# Loads default set of integrations. Do not remove.
default_config:
# Proxy Config
#homeassistant:
# external_url: "https://hassi.mpt.tmplab.org"
# http:
# use_x_forwarded_for: true
# trusted_proxies:
# - 10.255.0.2
# login_attempts_threshold: 5
# Text to speech
tts:
- platform: google_translate
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
prometheus:
sensor:
- platform: command_line
name: CPU Temperature
command: "cat /sys/class/thermal/thermal_zone0/temp"
# If errors occur, make sure configuration file is encoded as UTF-8
unit_of_measurement: "°C"
value_template: "{{ value }}"
EOF
## GRAFANA INSTALL
sudo apt-get install -y apt-transport-https software-properties-common wget sudo apt-get install -y apt-transport-https software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add - wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update sudo apt-get update
sudo apt-get install grafana sudo apt-get install grafana
cat <<EOF > /etc/systemd/system/grafana-server.service.d/override.conf
[Service]
# Give the CAP_NET_BIND_SERVICE capability
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
# A private user cannot have process capabilities on the host's user # This is probably useless: we don't need to start on a port lower than 3000
# namespace and thus CAP_NET_BIND_SERVICE has no effect. #cat <<EOF > /etc/systemd/system/grafana-server.service.d/override.conf
PrivateUsers=false #[Service]
## Give the CAP_NET_BIND_SERVICE capability
#CapabilityBoundingSet=CAP_NET_BIND_SERVICE
#AmbientCapabilities=CAP_NET_BIND_SERVICE
#
## A private user cannot have process capabilities on the host's user
## namespace and thus CAP_NET_BIND_SERVICE has no effect.
#PrivateUsers=false
#EOF
## PROMETHEUS INSTALL
curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest | grep browser_download_url | grep linux-amd64 | cut -d '"' -f 4 | wget -qi -
tar xvf prometheus*.tar.gz
cd prometheus*/
sudo mv prometheus promtool /usr/local/bin/
cat << EOF | sudo tee /etc/systemd/system/prometheus.service
[Unit]
Description=Prometheus
Documentation=https://prometheus.io/docs/introduction/overview/
Wants=network-online.target
After=network-online.target
[Service]
Type=simple
User=prometheus
Group=prometheus
ExecReload=/bin/kill -HUP $MAINPID
ExecStart=/usr/local/bin/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/lib/prometheus --web.console.templates=/etc/prometheus/consoles --web.console.libraries=/etc/prometheus/console_libraries --web.listen-address=0.0.0.0:9090 --web.external-url=
SyslogIdentifier=prometheus
Restart=always
[Install]
WantedBy=multi-user.target
EOF EOF
sudo systemctl daemon-reload sudo systemctl daemon-reload
sudo systemctl enable home-assistant@homeassistant.service sudo systemctl enable home-assistant@homeassistant.service
sudo systemctl start home-assistant@homeassistant.service sudo systemctl start home-assistant@homeassistant.service
sudo systemctl status home-assistant@homeassistant.service sudo systemctl status home-assistant@homeassistant.service
sudo systemctl enable prometheus
sudo systemctl start prometheus
sudo systemctl status prometheus
sudo systemctl enable grafana-server sudo systemctl enable grafana-server
sudo systemctl start grafana-server sudo systemctl start grafana-server
sudo systemctl status grafana-server sudo systemctl status grafana-server
echo " echo "
# create user in home ass # create user in home ass
# go to user profile in home ass # go to user profile in home ass
# get long lived access token like eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJlM2ZkY2VmZjYyODQ0OWQ5OGY2OTRlNmU2YjUxYzUyYSIsImlhdCI6MTY1MTg0ODU0NiwiZXhwIjoxOTY3MjA4NTQ2fQ.R6_My5eBUMcgompY3L3SbTUCTEIffQaNMUHyUw8sro0 # get long lived access token like eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJlM2ZkY2VmZjYyODQ0OWQ5OGY2OTRlNmU2YjUxYzUyYSIsImlhdCI6MTY1MTg0ODU0NiwiZXhwIjoxOTY3MjA4NTQ2fQ.R6_My5eBUMcgompY3L3SbTUCTEIffQaNMUHyUw8sro0
" "
read -p "Please provide your access token: " TOKEN cat << EOF | sudo tee /etc/prometheus/prometheus.yml
cat << EOF | sudo tee /etc/grafana/grafana.ini # File: /etc/prometheus/prometheus.yml
metrics: global:
wal_directory: /var/tmp/wal scrape_interval: 15s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
configs: evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
- name: integrations # scrape_timeout is set to the global default (10s).
# Attach these labels to any time series or alerts when communicating with
# external systems (federation, remote storage, Alertmanager).
external_labels:
monitor: 'example'
# Alertmanager configuration
alerting:
alertmanagers:
- static_configs:
- targets: ['localhost:9093']
# A scrape configuration containing exactly one endpoint to scrape:
# Here it's Prometheus itself.
scrape_configs: scrape_configs:
- job_name: integrations/hass - job_name: "hass"
scrape_interval: 60s
metrics_path: /api/prometheus metrics_path: /api/prometheus
bearer_token: "$TOKEN" authorization:
credentials: "$TOKEN"
scheme: http scheme: http
static_configs: static_configs:
- targets: ['localhost:8123'] - targets: ['localhost:8123']
EOF
read -p "Please provide your access token: " TOKEN
cat << EOF | sudo tee /etc/grafana/grafana.ini
metrics:
wal_directory: /tmp/wal
configs:
- name: integrations
scrape_configs:
- job_name: prometheus
metrics_path: /metrics
scheme: http
static_configs:
- targets: ['localhost:9090']
remote_write: remote_write:
- url: http://cortex:9009/api/prom/push - url: http://cortex:9009/api/prom/push
EOF EOF