GithubHelp home page GithubHelp logo

disk-usage-to-home-assistant's Introduction

Disk Usage to Home Assistant

This simple bash script connects to a given server via SSH, gets the filesystem usage via df and sends the data to Home Assistant. It includes a Healthchecks.io integration and the option to notify the user via Apprise API if the storage gets low. Originally written to monitor the storage usage of Hetzner Storage Boxes.

Installation

Prerequisites

  • Server to monitor with SSH access via passwordless SSH key and the df command available (e.g. Hetzner Storage Box)
  • Monitoring Server (e.g. generic Linux VM) that will run this script periodically
  • Home Assistant Long-Lived Access Token (create one via user profile -> scroll to bottom)
  • Optional but recommended: Healthchecks.io generated check URL to monitor this script so you get notified if something stops working
  • Optional: running instance of Apprise API or a similar service to notify you if the storage gets low (can also be achieved through a Home Assistant automation though)

Script Setup

  1. Save the script on any Linux server (not the one you want to get the storage stats from).
  2. Make the script executable with chmod +x disk-usage-to-home-assistant.sh.
  3. Edit the config section at the top of the script: nano disk-usage-to-home-assistant.sh
  4. Test the ssh command manually as this is the most likely part of the script to fail if setup incorrectly. This may also be needed once to accept the servers fingerprint. Adapt this command: ssh URL -l USER -p PORT -i PATH_TO_KEY df -h
  5. Test the whole script manually (./disk-usage-to-home-assistant.sh) and see if the values appear in Home Assistant (Developer Tools -> States -> Filter Entities for your configured server name).
  6. Schedule the script to run regularly, for example via cron (crontab -e and then add a line with the schedule and the path to the downloaded script: 0 3 * * * /home/YOURUSER/scripts/disk-usage-to-home-assistant.sh - find a schedule that works for you).

Optimised for Hetzner Storage Boxes

While optimised for Hetzner Storage Boxes this script should also work for normal Linux servers. When using Hetzner Storage Boxes remember to enable SSH access in the Hetzner control panel (Hetzner Robot). Use port 23 for SSH access. Beware that Hetzner may temporarily ban your IP if you try to connect with wrong credentials too often.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

Please see here.

disk-usage-to-home-assistant's People

Contributors

madwalnut avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.