Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT committed Feb 5, 2024
1 parent b66277c commit 25f80a5
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 48 deletions.
89 changes: 70 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,35 +1,38 @@
# Webhook Integration for Status Monitoring

## Overview

This repository provides a webhook integration for receiving updates related to incidents, maintenances, and component status changes. The integration supports different events associated with a status page.

# UP: Incidents and Maintenance
## UP: Incidents and Maintenance

[![Hex pm](http://img.shields.io/hexpm/v/up.svg?style=flat&x=1)](https://hex.pm/packages/up)

Minimalistic uptime server in Elixir with HTTP API and WebSocket SPA status page. See <a href="https://up.erp.uno">up.erp.uno</a>.
Minimalistic uptime server in Elixir with HTTP API and WebSocket SPA status page with proxy to Instatus.
See <a href="https://up.erp.uno">up.erp.uno</a>. UP supports mupltiple Accounts, multiple Sites per account,
multiple Components per Site, multiple Incidents per Components, multiple Maintenances per Incident,
multiple Subscription callback per Account.

Similar produts: Sematext, Hyperping, Cronitor, Atlassian Statuspage,
Better Uptime, Instatus, Freshstatus, Statuspal, Cachet, Vigil, StatusCast, Statping.

```elixir
get "/"
get "/incidents"
get "/incidents/:id"
put "/incidents"
put "/incidents/:id"
get "/sites"
get "/sites/:id"
put "/sites/:id"
get "/maintenance"
get "/maintenance/:id"
put "/maintenance"
put "/maintenance/:id"
get "/metrics"
get "/metrics/:id"
put "/metrics"
put "/metrics/:id"
get "/components"
get "/components/:type/:id"
put "/components"
get "/groups"
get "/groups/:type/:id"
put "/groups"
get "/users"
get "/users/:type/:id"
put "/users"
get "/components/:id"
put "/components/:id"
get "/subscriptions"
get "/subscriptions/:id"
put "/subscriptions/:id"
get "/accounts"
get "/accounts/:id"
put "/accounts/"
```

## Features
Expand Down Expand Up @@ -57,6 +60,8 @@ Accounts could only by created with security admin API key, which can
be set with `:application.set_env(:up, :security_admin, "secret")`.
Then you can add new accounts.

Create User:

```
$ curl -H "Auth: secret" -X PUT "http://localhost:5010/accounts/" -d @priv/account.json -v
[
Expand All @@ -68,6 +73,52 @@ $ curl -H "Auth: secret" -X PUT "http://localhost:5010/accounts/" -d @priv/accou
]
```

List Users:

```
$ curl -H "Auth: secret" -X GET "http://localhost:5010/accounts/" ; echo
[
{
"result": [
{
"id": "maxim-0012",
"key": "01707128300216989000",
"name": "Maksym Sokhatskyi",
"sites": []
}
],
"spec": "lst",
"type": "accounts"
}
]
```

### Sites Managements

```
$ curl -H "Auth: 01707128300216989000" -X GET "http://localhost:5010/sites/maxim-0012" ; echo
[
{
"result": [],
"spec": "get",
"type": "sites"
}
]
```

### Subscription Management

```
$ curl -H "Auth: 01707128300216989000" -X GET "http://localhost:5010/subscriptions/maxim-0012" ; echo
[
{
"result": [],
"spec": "get",
"type": "subscriptions"
}
]
```

## Webhook Formats

### Incident Updates
Expand Down
63 changes: 34 additions & 29 deletions lib/up_rest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ defmodule UP.HTTP do
get "/accounts" do get3(conn,auth(conn),"accounts",[],"lst") end
get "/accounts/:id" do get3(conn,auth(conn),"accounts",id,"get") end
put "/accounts/" do put3(conn,auth(conn),"accounts",[],"put") end
get "/sites" do get3(conn,auth(conn),"sites",[],"lst") end
get "/sites/:id" do get3(conn,auth(conn),"sites",id,"get") end
put "/sites/" do put3(conn,auth(conn),"sites",[],"put") end
get "/incidents" do get3(conn,auth(conn),"incidents",[],"lst") end
get "/incidents/:id" do get3(conn,auth(conn),"incidents",id,"get") end
put "/incidents" do put3(conn,auth(conn),"incidents",[],"put") end
Expand Down Expand Up @@ -103,35 +106,37 @@ defmodule UP.HTTP do

# GET LIST PATHWAY

def get3(conn,_,"subscriptions" = type,id,spec) do
:io.format 'GET:/#{type}/#{id}/#{spec}', []
send_resp(conn, 200, encode([%{"type" => type, "id" => id, "spec" => spec}])) end

def get3(conn,_,"accounts" = type,[],spec) do
accounts = :lists.map(fn x -> UP.Serial.fromRecord(x) end, :kvs.all("/#{type}/"))
:io.format 'GET:/#{type}/#{spec} LIST ~p', [accounts]
send_resp(conn, 200, encode([%{"type" => type, "spec" => spec, "result" => accounts }])) end

def get3(conn,_,"accounts" = type,id,spec) do
{:ok, account} = :kvs.get "/#{type}/", "#{id}"
:io.format 'GET:/#{type}/#{id}/#{spec} GET ~p', [account]
send_resp(conn, 200, encode([%{"type" => type, "spec" => spec, "result" => UP.Serial.fromRecord(account) }])) end

def get3(conn,_,"incidents" = type,id,spec) do
:io.format 'GET:/#{type}/#{id}/#{spec}', []
send_resp(conn, 200, encode([%{"type" => type, "spec" => spec}])) end

def get3(conn,_,"maintenance" = type,id,spec) do
:io.format 'GET:/#{type}/#{id}/#{spec}', []
send_resp(conn, 200, encode([%{"type" => type, "spec" => spec}])) end

def get3(conn,_,"metrics" = type,id,spec) do
:io.format 'GET:/#{type}/#{id}/#{spec}', []
send_resp(conn, 200, encode([%{"type" => type, "spec" => spec}])) end

def get3(conn,_,"components" = type,id,spec) do
:io.format 'GET:/#{type}/#{id}/#{spec}', []
send_resp(conn, 200, encode([%{"type" => type, "spec" => spec}])) end
def get3(conn, auth, "accounts" = type, [], spec) do
secAdmin = :application.get_env :up, :security_admin, "1707126861546831000"
case auth do
_ when auth == secAdmin ->
accounts = :lists.map(fn x -> UP.Serial.fromRecord(x) end, :kvs.all("/#{type}/"))
:io.format 'GET:/#{type}/#{spec} LIST ~p', [accounts]
send_resp(conn, 200, encode([%{"type" => type, "spec" => spec, "result" => accounts }]))
_ -> :io.format 'GET:/#{type} AUTH FAILED: ~p~n', [auth]
send_resp(conn, 200,
encode([%{ "error" => "Authorization",
"text" => "Security admin key doesn't match." }])) end end

def get3(conn, auth, type, _, spec) when type == "subscriptions"
or type == "sites"
or type == "incidents"
or type == "components"
or type == "metrics"
or type == "maintenance" do
case :kvs.get("/keys/", auth) do
{:ok,{:ref, x, name}} when x == auth ->
res = :lists.map(fn x -> UP.Serial.fromRecord(x) end, :kvs.all("/#{type}/#{name}/"))
:io.format 'GET:/#{type}/#{spec} NAME ~p LIST ~p', [name, res]
send_resp(conn, 200,
encode([%{ "type" => type,
"spec" => spec,
"result" => res }]))
_ -> :io.format 'GET:/#{type} AUTH FAILED: ~p~n', [auth]
send_resp(conn, 200,
encode([%{ "error" => "Authorization",
"text" => "Account key doesn't match." }]))
end end

# DELETE PATH WAY

Expand Down

0 comments on commit 25f80a5

Please sign in to comment.