-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 37b8ea9
Showing
21 changed files
with
835 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.cabal-sandbox | ||
dist | ||
.dockerignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.cabal-sandbox | ||
cabal.sandbox.config | ||
dist | ||
pinger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
FROM haskell:7.8 | ||
# mwotton/meanpath-build | ||
|
||
#RUN echo 43 | ||
|
||
RUN apt-get update | ||
#RUN apt-get install -y ghc-7.8.3 | ||
|
||
RUN apt-get install -y tmux make | ||
RUN apt-get install -y curl python | ||
|
||
WORKDIR /app | ||
|
||
#ENV PATH /opt/ghc/7.8.3/bin:/opt/cabal/1.20/bin/:$PATH | ||
|
||
ENV CONSOLE_URL=http://localhost:8000/checks.json | ||
|
||
CMD python -m SimpleHTTPServer >> /tmp/simple.log & \ | ||
/bin/bash |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM haskell:7.8 | ||
|
||
RUN apt-get update | ||
|
||
RUN apt-get install -y tmux make | ||
RUN apt-get install -y curl python | ||
|
||
|
||
ADD pinger /pinger | ||
|
||
|
||
CMD /pinger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
image: | ||
docker build -t pingbot . | ||
|
||
shell: image | ||
docker run -v $(shell pwd):/app -it pingbot | ||
|
||
# run this when brand new | ||
cabal-init: | ||
cabal update | ||
[ -d .cabal-sandbox ] || cabal sandbox init | ||
cabal install --only-dependencies | ||
|
||
install: image | ||
docker run -v $(shell pwd):/app pingbot ./build.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# Pinger bot for radalert | ||
|
||
The pingbot takes a checks.json (see example one) and then regularly heartbeats a status to HEART_URL. By default it will check about each minute, and allow about 10 seconds for a response. There are a few modes of checking - the default will just issue a HEAD request (efficient on the site as no content needs to be transferred). | ||
|
||
Rad. | ||
|
||
# Usage | ||
|
||
To use: ```export HEART_URL=http://requestb.in/15ejt921" && ./pinger```. | ||
|
||
Also set `CONSOLE_URL` and `CONSOLE_AUTH` and it will automatically load config from the appropriate url (has hard coded defaults) | ||
|
||
This will read from checks.json in the same directory (see the one in the root of this project for examples). | ||
|
||
The heartbeat will look something like (raw http body): | ||
``` | ||
{ | ||
"ttl" : 400, | ||
"state" : "OK", | ||
"tags" : ["blah"], | ||
"summary" : "OK", | ||
"api_key" : "1234", | ||
"check" : "https://www.google.com.au", | ||
"metric" :42 | ||
} | ||
``` | ||
|
||
|
||
And arrive every minute. requestb.in is a handy utility site - create an endpoint and you can have test POSTs go to it. | ||
|
||
The list of URLs to check will come from whatever CONSOLE_URL is set to (ie will fetch periodically what it is meant to check). Look at checks.json for the JSON format of check configuration. In DEV mode this will be served up automatically from localhost (so you can just edit the file and it will pick up the changes). | ||
|
||
|
||
By default, any < 500 code is considered success. You can specify an exact code, or optionally a body pattern. | ||
|
||
Rad. | ||
|
||
|
||
## building | ||
|
||
### development | ||
``` | ||
make shell # opens a shell in a docker container | ||
OPTIONAL: make cabal-init - if brand new setup | ||
cabal run Main # runs the program from source | ||
``` | ||
|
||
### binary | ||
|
||
``` | ||
make install | ||
``` | ||
$PWD/pinger is the binary you can run. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import Distribution.Simple | ||
main = defaultMain |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
name: app | ||
version: 0.1 | ||
cabal-version: >=1.10 | ||
build-type: Simple | ||
author: me | ||
|
||
executable app | ||
build-depends: | ||
base >= 4, | ||
HTTP, | ||
async, | ||
http-conduit, | ||
http-types, | ||
conduit, | ||
bytestring, | ||
transformers, | ||
random, | ||
aeson, | ||
text, | ||
regex-posix, | ||
unordered-containers, | ||
time, | ||
network-uri, | ||
base64-bytestring, | ||
case-insensitive, | ||
connection | ||
|
||
hs-source-dirs: src | ||
ghc-options: -Wall -rtsopts -threaded | ||
default-language: Haskell2010 | ||
main-is: Main.hs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/sh | ||
|
||
# To build the binary - likely to be called from Makefile inside a docker container | ||
make cabal-init | ||
cabal build | ||
cp dist/build/app/app $PWD/pinger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
[ | ||
|
||
|
||
{ | ||
"check": "http://gitlab.squarecloud.net.au/", | ||
"api_key": "1234", | ||
"tags": [ | ||
"gitlab.squarecloud.net.au" | ||
] | ||
}, | ||
{ | ||
"check": "https://dev.housenexus.com.au/", | ||
"api_key": "1234", | ||
"tags": [ | ||
"dev.housenexus.com.au" | ||
] | ||
} | ||
|
||
|
||
|
||
|
||
|
||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"metrics" : {"sizzle": 42} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
curl --data '{ | ||
"url": "http://130.211.134.49:7070/http://www.traviscistatus.com/metrics-display/9qbjll1hqc0z/day.json", | ||
"tags": [ | ||
"vimeo" | ||
] | ||
}' -u 8b1c905c4ccc93770f7380266df54efc: http://radalert.io/api/v1/checks |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
import SocketServer | ||
import BaseHTTPServer | ||
|
||
|
||
testurl = "http://www.vimeostatus.com/metrics-display/xz8v6gh243wt/day.json" | ||
|
||
import urllib2 | ||
import json | ||
|
||
|
||
def fetchMetrics (url): | ||
response = urllib2.urlopen(url) | ||
parsed = json.loads(response.read()) | ||
|
||
metric_list = parsed['metrics'] | ||
metrics = {} | ||
for m in metric_list: | ||
m_name = m['metric']['name'] | ||
m_val = 7 | ||
metrics[m_name] = m_val | ||
return { "metrics" : metrics } | ||
|
||
|
||
|
||
|
||
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): | ||
""" convert from statusio format to rad """ | ||
|
||
def do_GET(s): | ||
print s.path | ||
s.send_response(200) | ||
s.send_header("Content-type", "application/json") | ||
s.end_headers() | ||
print "ok" | ||
resp = fetchMetrics(s.path[1:]) | ||
print resp | ||
s.wfile.write(json.dumps(resp)) | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
port = 7070 | ||
httpd = SocketServer.TCPServer(("", port), MyHandler) | ||
print "Serving at port %d" % port | ||
httpd.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
import SocketServer | ||
import BaseHTTPServer | ||
|
||
|
||
testurl = "http://www.vimeostatus.com/metrics-display/xz8v6gh243wt/day.json" | ||
|
||
import urllib2 | ||
import json | ||
|
||
|
||
def fetchMetrics (url): | ||
response = urllib2.urlopen(url) | ||
parsed = json.loads(response.read()) | ||
|
||
metric_list = parsed['metrics'] | ||
metrics = {} | ||
for m in metric_list: | ||
m_name = m['metric']['name'] | ||
m_val = m['summary']['sum'] | ||
metrics[m_name] = m_val | ||
return { "metrics" : metrics } | ||
|
||
|
||
|
||
|
||
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): | ||
""" convert from statusio format to rad """ | ||
|
||
def do_GET(s): | ||
print s.path | ||
s.send_response(200) | ||
s.send_header("Content-type", "application/json") | ||
s.end_headers() | ||
print "ok" | ||
resp = fetchMetrics(s.path[1:]) | ||
print resp | ||
s.wfile.write(json.dumps(resp)) | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
port = 7070 | ||
httpd = SocketServer.TCPServer(("", port), MyHandler) | ||
print "Serving at port %d" % port | ||
httpd.serve_forever() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env python | ||
import SocketServer | ||
import BaseHTTPServer | ||
|
||
|
||
testurl = "http://www.vimeostatus.com/metrics-display/xz8v6gh243wt/day.json" | ||
|
||
import urllib2 | ||
import json | ||
|
||
|
||
def fetchMetrics (url): | ||
response = urllib2.urlopen(url) | ||
parsed = json.loads(response.read()) | ||
|
||
metric_list = parsed['metrics'] | ||
metrics = {} | ||
for m in metric_list: | ||
m_name = m['metric']['name'] | ||
m_val = m['summary']['mean'] | ||
metrics[m_name] = m_val | ||
return { "metrics" : metrics } | ||
|
||
|
||
|
||
|
||
class MyHandler(BaseHTTPServer.BaseHTTPRequestHandler): | ||
""" convert from statusio format to rad """ | ||
|
||
def do_GET(s): | ||
print s.path | ||
s.send_response(200) | ||
s.send_header("Content-type", "application/json") | ||
s.end_headers() | ||
print "ok" | ||
resp = fetchMetrics(s.path[1:]) | ||
print resp | ||
s.wfile.write(json.dumps(resp)) | ||
|
||
|
||
|
||
|
||
if __name__ == "__main__": | ||
port = 7070 | ||
httpd = SocketServer.TCPServer(("", port), MyHandler) | ||
print "Serving at port %d" % port | ||
httpd.serve_forever() |
Oops, something went wrong.