Code cleanup
parent
c7f165a4e3
commit
6d51b8cb40
44
README.md
44
README.md
|
@ -1 +1,45 @@
|
||||||
# am
|
# am
|
||||||
|
|
||||||
|
Simple alerts and monitoring server.
|
||||||
|
|
||||||
|
## Server Installation
|
||||||
|
|
||||||
|
The server (`cmd/amserver`) compiles to a dependency-free binary. Associated
|
||||||
|
files will be created or read from the working directory.
|
||||||
|
|
||||||
|
### Log and Alert Scripts
|
||||||
|
|
||||||
|
The server will call two scripts for log or alert events. These scripts need to
|
||||||
|
be executable and exist in the working directory. They need to be called
|
||||||
|
`log-action` and `alert-action`. They are called with two arguments:
|
||||||
|
|
||||||
|
1. The name of the source reporting the log or alert.
|
||||||
|
1. The associated text.
|
||||||
|
|
||||||
|
### Running
|
||||||
|
|
||||||
|
Run the server with a listen address:
|
||||||
|
|
||||||
|
```amserver -listen example.com:443```
|
||||||
|
|
||||||
|
If the port is 443, then the server will serve of https and automatically
|
||||||
|
acquire a certificate from letsencrypt.
|
||||||
|
|
||||||
|
### Default User Account
|
||||||
|
|
||||||
|
By default, an account is created with username `root` and password `root1234`.
|
||||||
|
|
||||||
|
## Source Usage
|
||||||
|
|
||||||
|
Sources can perform three actions: `ping`, `log`, or `alert`. Actions are sent
|
||||||
|
as standard HTTP POST requests to the URL
|
||||||
|
`https://example.com/report/<APIKey>`.
|
||||||
|
|
||||||
|
For example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
curl \
|
||||||
|
--data-urlencode "action=alert" \
|
||||||
|
--data-urlencode "text=An alert!" \
|
||||||
|
https://example.com/report/$API_KEY
|
||||||
|
```
|
2
db.go
2
db.go
|
@ -36,7 +36,7 @@ func newDB(dbPath string) (*dbal, error) {
|
||||||
_ = db.UserInsert(User{
|
_ = db.UserInsert(User{
|
||||||
Username: `root`,
|
Username: `root`,
|
||||||
Admin: true,
|
Admin: true,
|
||||||
}, `rootroot`)
|
}, `root1234`)
|
||||||
|
|
||||||
return db, nil
|
return db, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,9 +93,6 @@
|
||||||
|
|
||||||
<dt>Alert Timeout (sec)</dt>
|
<dt>Alert Timeout (sec)</dt>
|
||||||
<dd>{{.AlertTimeout}}</dd>
|
<dd>{{.AlertTimeout}}</dd>
|
||||||
|
|
||||||
<dt>Alerted At</dt>
|
|
||||||
<dd>{{.AlertedAt.Format "2006-01-02 15:04"}}</dd>
|
|
||||||
</dl>
|
</dl>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
@ -128,7 +125,7 @@
|
||||||
</textarea>
|
</textarea>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="AlertTimeout">Alert Timeout:</label>
|
<label for="AlertTimeout">Alert Timeout (Sec):</label>
|
||||||
<input type="number" id="AlertTimeout" name="AlertTimeout" value="{{.Source.AlertTimeout}}">
|
<input type="number" id="AlertTimeout" name="AlertTimeout" value="{{.Source.AlertTimeout}}">
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -189,9 +189,6 @@ var tmpls = `
|
||||||
|
|
||||||
<dt>Alert Timeout (sec)</dt>
|
<dt>Alert Timeout (sec)</dt>
|
||||||
<dd>{{.AlertTimeout}}</dd>
|
<dd>{{.AlertTimeout}}</dd>
|
||||||
|
|
||||||
<dt>Alerted At</dt>
|
|
||||||
<dd>{{.AlertedAt.Format "2006-01-02 15:04"}}</dd>
|
|
||||||
</dl>
|
</dl>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
@ -224,7 +221,7 @@ var tmpls = `
|
||||||
</textarea>
|
</textarea>
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<label for="AlertTimeout">Alert Timeout:</label>
|
<label for="AlertTimeout">Alert Timeout (Sec):</label>
|
||||||
<input type="number" id="AlertTimeout" name="AlertTimeout" value="{{.Source.AlertTimeout}}">
|
<input type="number" id="AlertTimeout" name="AlertTimeout" value="{{.Source.AlertTimeout}}">
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
|
|
|
@ -110,7 +110,7 @@ func handle_admin(path string, h func(w http.ResponseWriter, r *http.Request)) {
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
func handleRoot(w http.ResponseWriter, r *http.Request) {
|
func handleRoot(w http.ResponseWriter, r *http.Request) {
|
||||||
respondRedirect(w, r, "/user/list")
|
respondRedirect(w, r, "/log/list")
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
Reference in New Issue