parent
4e27497960
commit
92def89fdc
49
README.md
49
README.md
|
@ -1,32 +1,37 @@
|
|||
# Monit Dashboard
|
||||
|
||||
## Description
|
||||
Python web application to get a dashboard of a bunch of [Monit][monit]
|
||||
servers at a glance.
|
||||
|
||||
Python web application to get a dashboard of a bunch of [Monit] servers at a
|
||||
glance.
|
||||
|
||||
## How does it work?
|
||||
Every 300 seconds the application ask for the data served by the
|
||||
Monit built-in web server in a XMl report from each configured server.
|
||||
Then, thanks to the built-in web server, it is displayed in a single
|
||||
HTML page.
|
||||
|
||||
Every 300 seconds (hardcoded) the application ask for the data served by the
|
||||
Monit built-in web server in a XMl report from each configured server. Then,
|
||||
thanks to the built-in web server, it is displayed in a single HTML page.
|
||||
|
||||
## Pre requisites
|
||||
|
||||
### Debian GNU/Linux
|
||||
|
||||
#### Web.py framework
|
||||
|
||||
- `apt install python-webpy`
|
||||
|
||||
#### Python libraries
|
||||
|
||||
- `apt install python-xmltodict python-requests`
|
||||
|
||||
### CentOS
|
||||
|
||||
#### Python PIP
|
||||
|
||||
- `yum install epel-release`
|
||||
- `yum install python-pip`
|
||||
|
||||
#### Web.py framework
|
||||
|
||||
- `pip install web.py`
|
||||
|
||||
#### Python libaries
|
||||
|
@ -34,26 +39,30 @@ HTML page.
|
|||
- `yum install python-requests python-xmltodict python-simplejson`
|
||||
|
||||
## Requisites
|
||||
- Config file `conf/servers.json` prior run. You might find a sample
|
||||
file at `conf/servers.json.example`.
|
||||
|
||||
- Config file `conf/servers.json` prior run. You might find a sample file at
|
||||
`conf/servers.json.example`.
|
||||
- Please see [Config](#config) section for further details.
|
||||
|
||||
## Run
|
||||
|
||||
`./bin/monit-dashboard.py`
|
||||
|
||||
By default, it will be reachable at http://localhost:8080. You might
|
||||
change the port by adjusting `app.run(port=8080)` in
|
||||
`bin/monit-dashboard.py` file.
|
||||
By default, it will be reachable at <http://localhost:8080>. You might change
|
||||
the port by adjusting `app.run(port=8080)` in `bin/monit-dashboard.py` file.
|
||||
|
||||
## References
|
||||
|
||||
- [web.py 0.3 tutorial][webpy-tutorial]
|
||||
- [Learn Python the hard way, ex 50][lpthw]
|
||||
- [A template example][template-example]
|
||||
- [How to change HTTP server port][port]
|
||||
|
||||
## Config
|
||||
|
||||
- Placed in `conf/servers.json`
|
||||
- Sample settings as follows:
|
||||
|
||||
```
|
||||
{
|
||||
"My server to monit": {
|
||||
|
@ -65,21 +74,23 @@ change the port by adjusting `app.run(port=8080)` in
|
|||
```
|
||||
|
||||
# Credits
|
||||
|
||||
- [Original idea][idea]
|
||||
- Frontend support: Júlia Vázquez
|
||||
- [Icons][icons]
|
||||
- [Icons]
|
||||
- [Accordion menu][accordion]
|
||||
|
||||
# License
|
||||
|
||||
[AGPL][license]
|
||||
|
||||
[accordion]: http://www.w3schools.com/howto/howto_js_accordion.asp
|
||||
[icons]: https://commons.wikimedia.org/wiki/User:House
|
||||
[idea]: https://imil.net/blog/2016/03/16/Fetch-monit-status-in-JSON/
|
||||
[license]: LICENSE
|
||||
[lpthw]: https://learnpythonthehardway.org/book/ex50.html
|
||||
[monit]: https://mmonit.com/monit/
|
||||
[port]: https://stackoverflow.com/questions/14444913/web-py-specify-address-and-port
|
||||
[template-example]: https://stackoverflow.com/questions/28508869/using-web-py-to-dynamically-output-values-from-process-initiated-by-form-submiss
|
||||
[webpy]: http://webpy.org/
|
||||
[webpy-tutorial]: http://webpy.org/tutorial3.en
|
||||
[port]: https://stackoverflow.com/questions/14444913/web-py-specify-address-and-port
|
||||
[lpthw]: https://learnpythonthehardway.org/book/ex50.html
|
||||
[template-example]: https://stackoverflow.com/questions/28508869/using-web-py-to-dynamically-output-values-from-process-initiated-by-form-submiss
|
||||
[idea]: https://imil.net/blog/2016/03/16/Fetch-monit-status-in-JSON/
|
||||
[icons]: https://commons.wikimedia.org/wiki/User:House
|
||||
[accordion]: http://www.w3schools.com/howto/howto_js_accordion.asp
|
||||
[license]: LICENSE
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import web
|
||||
import requests, xmltodict, json, os, sys
|
||||
import requests
|
||||
import xmltodict
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import datetime
|
||||
|
||||
urls = ('/', 'index',
|
||||
|
@ -11,13 +15,14 @@ urls = ('/', 'index',
|
|||
app = web.application(urls, globals())
|
||||
render = web.template.render('templates/', base="layout")
|
||||
|
||||
## Uncomment to turn debug off
|
||||
# Uncomment to turn debug off
|
||||
web.config.debug = False
|
||||
|
||||
## Variables
|
||||
# Variables
|
||||
output = []
|
||||
|
||||
## Functions
|
||||
# Functions
|
||||
|
||||
|
||||
def getMonit():
|
||||
output = []
|
||||
|
@ -30,7 +35,8 @@ def getMonit():
|
|||
|
||||
for site in cf:
|
||||
s = cf[site]
|
||||
r = requests.get(s['url'] + xmlQuery, auth = (s['user'], s['passwd']))
|
||||
r = requests.get(s['url'] + xmlQuery,
|
||||
auth=(s['user'], s['passwd']))
|
||||
|
||||
allstat = json.loads(json.dumps(xmltodict.parse(r.text)['monit']))
|
||||
|
||||
|
@ -50,22 +56,28 @@ def getMonit():
|
|||
print(datetime.datetime.now())
|
||||
return(output)
|
||||
|
||||
## Classes
|
||||
# Classes
|
||||
|
||||
|
||||
class monitDashboard(web.application):
|
||||
|
||||
def run(self, port=8080, *middleware):
|
||||
func = self.wsgifunc(*middleware)
|
||||
return web.httpserver.runsimple(func, ('0.0.0.0', port))
|
||||
|
||||
|
||||
class index(object):
|
||||
|
||||
def GET(self):
|
||||
return render.index(output=getMonit(), now=datetime.datetime.now())
|
||||
|
||||
|
||||
class help(object):
|
||||
|
||||
def GET(self):
|
||||
return render.help()
|
||||
|
||||
## Main
|
||||
# Main
|
||||
if __name__ == "__main__":
|
||||
app = monitDashboard(urls, globals())
|
||||
app.run(port=8080)
|
||||
|
|
|
@ -1,15 +1,18 @@
|
|||
$def with (content)
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<title>Monit Dashboard</title>
|
||||
<link rel="stylesheet" type="text/css" href="static/monit-dashboard.css" />
|
||||
<meta http-equiv="refresh" content="300">
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
$:content
|
||||
|
||||
<a href="/">Home</a> | <a href="/help">Help</a>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in a new issue