Coder Social home page Coder Social logo

ruby-grafana-matrix's Introduction

Grafana Matrix

A Grafana webhook ingress for sending Matrix notifications

Working:

  • Simple notifications
  • Authenticated requests

TODO:

  • Proper styling

Installation / Usage

Until a more proper release is done;
Download the git repo, instantiate the bundle, create a proper configuration file, and launch the server

git clone https://github.com/ananace/ruby-grafana-matrix
cd ruby-grafana-matrix
bundle install --path=vendor
cp config.yml.example config.yml
vi config.yml
# Edit the configuration to suit your requirements

bundle exec rackup

You would then add the ingester as a Grafana webhook channel like so - albeit with port 9292 unless changed;

Grafana config

Docker

Build the image:

docker build -t ruby-grafana-matrix:latest .

Create a proper configuration file:

cp config.yml.example config.yml
vi config.yml

Run the resulting container, and mount your config.yml inside of it:

docker run -v $PWD/config.yml:/app/config.yml --name ruby-grafana-matrix ruby-grafana-matrix:latest

If running the container on the same host as Grafana, you can attach it to the same Docker network and use the container name in the Grafana webhook URL.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ananace/ruby-grafana-matrix

License

The gem is available as open source under the terms of the MIT License.

ruby-grafana-matrix's People

Contributors

ananace avatar jeffcasavant avatar lovelaced avatar spiritcroc avatar su-ex avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar  avatar

ruby-grafana-matrix's Issues

Updated Docker container

Could you kindly update ananace/grafana-matrix on Docker Hub? It was updated 2 years ago while the latest commit in this repo was 21 days ago.

wrong number of arguments

Hello, when I try to use the webhook I get the following error.

curl -X POST http://xxx.xxx.xx:9292/hook?rule=hq -d "Content-Length: 0"

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<HTML>
  <HEAD><TITLE>Internal Server Error</TITLE></HEAD>
  <BODY>
    <H1>Internal Server Error</H1>
    wrong number of arguments (given 0, expected 1)
    <HR>
    <ADDRESS>
     WEBrick/1.6.0 (Ruby/2.7.2/2020-10-01) at
     xxx.xxx.xx:9292
    </ADDRESS>
  </BODY>
</HTML>

This is the config file, are dummy values:

# Set up your HS connections
matrix:
- name: matrix-org
  url: 'https://matrix.org'
  # Create a user - log that user in using a post request
  # curl -XPOST -d '{"type": "m.login.password",
  #                  "user":"grafana",
  #                  "password":"2m4ny53cr3t5"}'
  #      "https://my-matrix-server/_matrix/client/r0/login"
  # Fill that access token in here
  access_token: 'Y2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9uY2F0aW9u'
  #device_id: <device> # Optional
#- name: matrix-priv
#  url: 'https://private.matrix.org'
#  access_token: '<token>'

# The default message type for messages, should be either m.text or m.notice,
# defaults to m.text
msgtype: m.text

# Set up notification ingress rules
rules:
- name: hq               # Name of the rule
  room: "!Y2F0aW9u:matrix.org" # Room or ID
  matrix: matrix-org     # The Matrix HS to use - defaults to first one
  msgtype: m.notice
  # The following values are optional:
  #image: true           # Attach image to the notification?
  #embed_image: true     # Upload and embed the image into the message?
  #templates:
    # Templates to use when rendering the notification, available placeholders:
    #   %TEMPLATES% - lib/grafana_matrix/templates
    #   $<env>      - Environment variables
    #html: "%TEMPLATES%/html.erb" # Path to HTML template
    #plain: "%TEMPLATES%/plain.erb" # Path to plaintext template
  #auth:
    #user: example
    #pass: any HTTP encodable string
#- name: other-hq
#  room: "#hq:private.matrix.org
#  matrix: matrix-priv

# To use the webhook, you need to configure it into Grafana as:
#
# Url: http://<server address>:<port>/hook?rule=<rule name>
# Http Method: POST

I am missing something?

Receiving 404 Not Found with existing rule

In the config.yml there is the following entry:

rules:
- name: myrule
  room: "#myroom:matrix.example.com"
  matrix: my-matrix-config

Grafana always reports an error. Looking with curl:

curl -X POST -d '' http://[xxx:xxxx:xxxx:xxxx::1]:4567/hook?rule=myrule
No such rule configured

The server output says

xxx:xxxx:xxxx:xxxx::1 - - [21/Feb/2020:13:18:34 CET] "POST /hook?rule=myrule HTTP/1.1" 404 23
- -> /hook?rule=myrule

Am I doing something wrong? Its definitely loading the correct config file. Changing the interface works, for example.

Incorrect webhook settings in README.md

Seems that the webhook URL should now contain port 9292 and not 4567.

I've been running this with docker and it broke at some point. At least the port had to be changed, but I'm not sure if there's something else since the notification test in grafana fails and log says msg="failed to send notification" logger=alerting.notifier uid= error="Webhook response status 404 Not Found". I'll have to investigate more.

Update: found the problem and created issue #13

Broken configuration parsing of rules

Seems that configuration parsing of rules is broken and results in empty list of rules. I'm using docker (so ruby 2.6) to run this project. In practice this means that the server always responds 404 even for valid requests.

I found that the commit that breaks this is 23c82f9.

This fixes the issue:

--- a/lib/grafana_matrix/config.rb
+++ b/lib/grafana_matrix/config.rb
@@ -113,7 +113,7 @@ module GrafanaMatrix
         client_data = client_data.dup
 
         # Symbolize keys
-        client_data.each_key do |key|
+        client_data.keys.each do |key|
           client_data[(key.to_sym rescue key)] = client_data.delete key
         end
 
@@ -129,7 +129,7 @@ module GrafanaMatrix
         rule_data = rule_data.dup
 
         # Symbolize keys
-        rule_data.each_key do |key|
+        rule_data.keys.each do |key|
           rule_data[(key.to_sym rescue key)] = rule_data.delete key
         end

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.