Skip to content

Commit

Permalink
Cleaned up from secrets
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelneale committed Apr 4, 2016
0 parents commit 37b8ea9
Show file tree
Hide file tree
Showing 21 changed files with 835 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.cabal-sandbox
dist
.dockerignore
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.cabal-sandbox
cabal.sandbox.config
dist
pinger
19 changes: 19 additions & 0 deletions Dockerfile
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
12 changes: 12 additions & 0 deletions Dockerfile.production
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
14 changes: 14 additions & 0 deletions Makefile
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
53 changes: 53 additions & 0 deletions README.md
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.
2 changes: 2 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
31 changes: 31 additions & 0 deletions app.cabal
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
6 changes: 6 additions & 0 deletions build.sh
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
23 changes: 23 additions & 0 deletions checks.json
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"
]
}





]
3 changes: 3 additions & 0 deletions metrics.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"metrics" : {"sizzle": 42}
}
6 changes: 6 additions & 0 deletions scrapers/addcheck
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
47 changes: 47 additions & 0 deletions scrapers/constant.py
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()
47 changes: 47 additions & 0 deletions scrapers/statusio.py
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()
47 changes: 47 additions & 0 deletions scrapers/statusio_mean.py
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()
Loading

0 comments on commit 37b8ea9

Please sign in to comment.