Code Monkey home page Code Monkey logo

raphaelbernhart / healthznerbot Goto Github PK

View Code? Open in Web Editor NEW
24.0 1.0 1.0 195 KB

A discord bot to get periodically updates of the health status of your hetzner cloud machines with several commands such as !servers to check the workload metrics.

Home Page: https://www.producthunt.com/products/healthznerbot

License: GNU General Public License v3.0

TypeScript 100.00%
hetzner devops discord discord-bot health-status hetzner-cloud-machines cloud cloud-machines vps server

healthznerbot's Introduction

Healthzner Bot

A discord bot to periodically get updates of the health status of your hetzner cloud machines.

Installation

Make sure you have Docker installed and properly configured on your system before following these steps. Additionally, ensure you have the necessary permissions and access to create and configure a Discord Bot, as well as the required credentials for accessing Hetzner cloud APIs.

Docker

  1. Copy the .env.example file by running the following command in your terminal:

    wget https://raw.githubusercontent.com/raphaelbernhart/healthznerbot/main/.env.example
    
  2. Configure the .env file with your desired settings. You can open the file using a text editor and modify the values accordingly. Ensure you provide the necessary information, such as your Discord Bot token, Hetzner cloud API credentials, and other required configuration options.

  3. Once you've finished configuring the .env file, rename it to ".env". You can do this by running the following command:

    mv .env.example .env
    
  4. Pull the Docker image for the Discord Bot by executing the following command:

    docker pull ghcr.io/raphaelbernhart/healthznerbot:latest
    
  5. Launch the Discord Bot using Docker, specifying the .env file for configuration. Run the following command:

    docker run --env-file .env ghcr.io/raphaelbernhart/healthznerbot:latest
    

    This command will start the Docker container and run the Discord Bot using the provided .env file.

  6. The Discord Bot will now periodically send updates of Hetzner cloud machines to the specified Discord channel. Also you can manually get the status with the /status command and the metrics/information about the servers via the /servers or /metrics command.

Build yourself

  1. Copy the project to your local machine git clone https://github.com/raphaelbernhart/healthznerbot.git
  2. Change directory to Healthznerbot cd healthznerbot
  3. Rename the .env.example to .env and configure it with your credentials and wishes
  4. Run the command npm i to install the dependencies
  5. Run npm run build to build the bot
  6. Change directory to dist cd ./dist
  7. And finally run npm run start to run the bot

Commands

!servers/!metrics - Lists all Servers in a project including information like cpu and network workload and IP's
healthznerbot-ui.png !status - Get the current Status of the Servers. Returning 'Alle Server sind online!' if all Servers are up. Returns '❌ Server SERVERNAME(IP_ADDR) ist momentan offline.' (English is also available)

Configuration

The configuration is made with environment variables.

Rename the .env.example to .env and configure it with your credentials and wishes

  • DISCORD_TOKEN: The Discord Token which you have to generate on the Discord Developer Portal (https://discord.com/developers/applications)
  • DISCORD_CHANNEL: The Channel ID from the channel in which you want the bot to be
  • HETZNER_TOKEN: The Hetzner Cloud API Token which you have to generate on the Hetzner Cloud Console (https://docs.hetzner.cloud/#getting-started)
  • STATUS_UPDATE_INTERVAL: How often status updates will occure (in minutes) e.g. 2.5 = every two and a half minutes
  • SERVER_METRICS_PERIOD: Period to get metrics such as CPU and Network Workload (in minutes) e.g. 15 get the average workload from the last 15 minutes
  • LANGUAGE: Language, currently are only german and english supported (de/en)

healthznerbot's People

Contributors

raphaelbernhart avatar rb-clubdrei avatar renovate-bot avatar renovate[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

healthznerbot's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

dockerfile
dockerfile
  • node 20.11.0
  • node 20.11.0-alpine
github-actions
.github/workflows/Push-Image.yaml
  • actions/checkout v4
  • martinbeentjes/npm-get-version-action v1.3.1
npm
package.json
  • @discordjs/rest ^2.2.0
  • axios ^1.6.5
  • consola ^3.2.3
  • dayjs ^1.11.10
  • discord.js 14.14.1
  • dotenv ^16.3.1
  • hcloud-js ^1.4.1
  • @types/node 20.11.0
  • @types/ws 8.5.10
  • nodemon 3.0.3
  • ts-node ^10.9.2
  • typescript 5.3.3
  • node >=20.11.0

  • Check this box to trigger a request for Renovate to run again on this repository

Improve Hetzner API error catching

The error catching of the hcloud sdk is not helpful while debugging.

Possible improvement:
log out:

  • Status code
  • status message
  • path
  • method
  • env token key (⚠️ KEY ONLY)

Error log:

> [email protected] start /app
> node .

◐ Start registering 3 commands(/).
✔ Successfully registered 3 commands(/).
◐ Logging in the bot
ℹ Registering Status command worker
✔ Finished registering of Status command worker
✔ Logged in as Healthznerbot
            [Symbol(triggerId)]: 111335
          },
          [Symbol(kBuffer)]: null,
          [Symbol(kBufferCb)]: null,
          [Symbol(kBufferGen)]: null,
          [Symbol(kCapture)]: false,
          [Symbol(kSetNoDelay)]: false,
          [Symbol(kSetKeepAlive)]: false,
          [Symbol(kSetKeepAliveInitialDelay)]: 0,
          [Symbol(kBytesRead)]: 0,
          [Symbol(kBytesWritten)]: 232,
          [Symbol(connect-options)]: {
            rejectUnauthorized: true,
            checkServerIdentity: [Function: checkServerIdentity],
            minDHSize: 1024,
            session: [Buffer [Uint8Array]],
            maxRedirects: 21,
            maxBodyLength: 10485760,
            protocol: 'https:',
            path: null,
            method: 'GET',
            headers: [Object],
            agent: undefined,
            agents: [Object],
            auth: undefined,
            hostname: 'api.hetzner.cloud',
            port: 443,
            nativeProtocols: [Object],
            pathname: '/v1/servers',
            _defaultAgent: [Agent],
            host: 'api.hetzner.cloud',
            noDelay: true,
            servername: 'api.hetzner.cloud',
            _agentKey: 'api.hetzner.cloud:443:::::::::::::::::::::',
            encoding: null,
            singleUse: true
          }
        },
        incoming: null,
        outgoing: [Circular *2],
        maxHeaderPairs: 2000,
        _consumed: false,
        onIncoming: [Function: parserOnIncomingClient],
        joinDuplicateHeaders: undefined,
        [Symbol(resource_symbol)]: HTTPClientAsyncResource {
          type: 'HTTPINCOMINGMESSAGE',
          req: [Circular *2]
        }
      },
      maxHeadersCount: null,
      reusedSocket: false,
      host: 'api.hetzner.cloud',
      protocol: 'https:',
      _redirectable: [Circular *4],
      [Symbol(kCapture)]: false,
      [Symbol(kBytesWritten)]: 0,
      [Symbol(kNeedDrain)]: false,
      [Symbol(corked)]: 0,
      [Symbol(kOutHeaders)]: [Object: null prototype] {
        accept: [ 'Accept', 'application/json, text/plain, */*' ],
        'user-agent': [ 'User-Agent', 'hcloud-js/1.4.1' ],
        authorization: [
        ],
        host: [ 'Host', 'api.hetzner.cloud' ]
      },
      [Symbol(errored)]: null,
      [Symbol(kHighWaterMark)]: 16384,
      [Symbol(kRejectNonStandardBodyWrites)]: false,
      [Symbol(kUniqueHeaders)]: null,
      [Symbol(kError)]: undefined
    },
    _currentUrl: 'https://api.hetzner.cloud/v1/servers',
    _timeout: null,
    [Symbol(kCapture)]: false
  },
  response: undefined,
  isAxiosError: true,
  toJSON: [Function: toJSON]
}

bot can't start

[Config Check] Some env variable for discord is invalid
 ELIFECYCLE  Command failed with exit code 1.

Fix uncaptured exit of application (hcloud error)

Debug:
Debug the application in production after #70 is merged.

Possible solution:

  • Catch the hcloud errors and do not exit the application on an error.
  • try to check why hcloud is throwing errors
  • upgrade the hcloud package? (testing!)

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.