diff --git a/Procfile b/Procfile new file mode 100644 index 00000000..7a229f65 --- /dev/null +++ b/Procfile @@ -0,0 +1,5 @@ +a1: ./alertmanager -log.level=debug -storage.path=$TMPDIR/a1 -web.listen-address=:9093 -mesh.hardware-address=00:00:00:00:00:01 -mesh.nickname=a -mesh.listen-address=:8001 -config.file=examples/ha/alertmanager.yaml +a2: ./alertmanager -log.level=debug -storage.path=$TMPDIR/a2 -web.listen-address=:9094 -mesh.hardware-address=00:00:00:00:00:02 -mesh.nickname=b -mesh.listen-address=:8002 -mesh.peer=127.0.0.1:8001 -config.file=examples/ha/alertmanager.yaml +a3: ./alertmanager -log.level=debug -storage.path=$TMPDIR/a3 -web.listen-address=:9095 -mesh.hardware-address=00:00:00:00:00:03 -mesh.nickname=c -mesh.listen-address=:8003 -mesh.peer=127.0.0.1:8001 -config.file=examples/ha/alertmanager.yaml +wh: ./examples/ha/webhook.py + diff --git a/examples/ha/send_alerts.sh b/examples/ha/send_alerts.sh new file mode 100755 index 00000000..50735536 --- /dev/null +++ b/examples/ha/send_alerts.sh @@ -0,0 +1,40 @@ +alerts1='[ + { + "labels": { + "alertname": "DiskRunningFull", + "dev": "sda1", + "instance": "example1" + } + }, + { + "labels": { + "alertname": "DiskRunningFull", + "dev": "sda2", + "instance": "example1" + } + }, + { + "labels": { + "alertname": "DiskRunningFull", + "dev": "sda1", + "instance": "example2" + } + }, + { + "labels": { + "alertname": "DiskRunningFull", + "dev": "sdb2", + "instance": "example2" + } + }, + { + "labels": { + "alertname": "DiskRunningFull", + "dev": "sda1", + "instance": "example3" + } + } +]' +curl -XPOST -d"$alerts1" http://localhost:9093/api/v1/alerts +curl -XPOST -d"$alerts1" http://localhost:9094/api/v1/alerts +curl -XPOST -d"$alerts1" http://localhost:9095/api/v1/alerts diff --git a/examples/ha/webhook.py b/examples/ha/webhook.py new file mode 100755 index 00000000..ad5f6810 --- /dev/null +++ b/examples/ha/webhook.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python +# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE +# Written by Nathan Hamiel (2010) + +from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler +from optparse import OptionParser + +class RequestHandler(BaseHTTPRequestHandler): + + def do_GET(self): + + request_path = self.path + + print("\n----- Request Start ----->\n") + print(request_path) + print(self.headers) + print("<----- Request End -----\n") + + self.send_response(200) + self.end_headers() + + def do_POST(self): + + request_path = self.path + + print("\n----- Request Start ----->\n") + print(request_path) + + request_headers = self.headers + content_length = request_headers.getheaders('content-length') + length = int(content_length[0]) if content_length else 0 + + print(request_headers) + print(self.rfile.read(length)) + print("<----- Request End -----\n") + + self.send_response(200) + self.end_headers() + + do_PUT = do_POST + do_DELETE = do_GET + +def main(): + port = 5001 + print('Listening on localhost:%s' % port) + server = HTTPServer(('', port), RequestHandler) + server.serve_forever() + + +if __name__ == "__main__": + parser = OptionParser() + parser.usage = ("Creates an http-server that will echo out any GET or POST parameters\n" + "Run:\n\n" + " reflect") + (options, args) = parser.parse_args() + + main()