Skip to content

Commit 145a5cf

Browse files
committed
initial commit
1 parent 1e603c8 commit 145a5cf

File tree

3 files changed

+134
-0
lines changed

3 files changed

+134
-0
lines changed

README.md

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,83 @@
11
# http_monitor
22
py3status module for monitoring http services
3+
4+
## Prerequisites
5+
6+
This is an i3 / py3status module, so you'll need those first off.
7+
8+
## Installation
9+
10+
```bash
11+
git clone git@github.com:mcgillij/http_monitor.git ~/.i3/py3status/
12+
```
13+
14+
## Configuration
15+
16+
Next you will need to add the services you want to monitor, and optionally choose some appropriate emoji's.
17+
18+
Here's an excerpt from my configuration file located at *~/.config/i3/i3status.conf*.
19+
20+
**~/.config/i3/i3status.conf**
21+
22+
```bash
23+
...
24+
general {
25+
colors = true
26+
interval = 15
27+
}
28+
29+
order += "http_monitor apache"
30+
order += "http_monitor medusa"
31+
order += "http_monitor pihole"
32+
order += "http_monitor nextcloud"
33+
order += "http_monitor plex"
34+
order += "http_monitor virtualbox"
35+
order += "http_monitor airsonic"
36+
order += "clock"
37+
order += "mail"
38+
...
39+
40+
http_monitor 'nextcloud' {
41+
service_location = "http://yourserver:8181"
42+
service_name = ''
43+
}
44+
45+
http_monitor 'virtualbox' {
46+
service_location = "http://yourserver:81/vb/"
47+
service_name = '💻'
48+
}
49+
50+
http_monitor 'plex' {
51+
service_location = "http://yourserver:32400/web/index.html#"
52+
service_name = '🎥'
53+
}
54+
55+
http_monitor 'airsonic' {
56+
service_location = "http://yourserver:4040"
57+
service_name = '🍃'
58+
}
59+
60+
http_monitor 'pihole' {
61+
service_location = "http://yourserver:80"
62+
service_name = '🕳️ '
63+
}
64+
65+
http_monitor 'apache' {
66+
service_location = "http://yourserver:81"
67+
service_name = '🪶'
68+
}
69+
70+
http_monitor 'medusa' {
71+
service_location = "http://yourserver:8081"
72+
service_name = '🐍'
73+
}
74+
```
75+
## Configuration Options
76+
77+
You can pass in the following configuration options:
78+
79+
* service_location
80+
* service_name
81+
* timeout
82+
* cache_timeout
83+

http_monitor.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Module to display the status of a remote web service
4+
"""
5+
6+
class Py3status:
7+
cache_timeout = 600
8+
service_name = "test"
9+
service_location = "http://example.com"
10+
timeout = 3
11+
status_good = "🟢"
12+
status_bad = "🔴"
13+
format = '{service_name}: {status}'
14+
15+
def _get_status(self):
16+
try:
17+
self.py3.log(self.service_location)
18+
status = self.py3.request(self.service_location, timeout=self.timeout)
19+
if status.status_code != 200:
20+
return self.status_bad
21+
return self.status_good
22+
23+
except self.py3.RequestException as re:
24+
return self.status_bad
25+
26+
def http_monitor(self):
27+
status = self._get_status()
28+
full_text = self.py3.safe_format(self.format, {'service_name': self.service_name, 'status': status})
29+
return {
30+
'full_text': full_text,
31+
'cached_until': self.py3.time_in(self.cache_timeout)
32+
}
33+
34+
35+
if __name__ == "__main__":
36+
from py3status.module_test import module_test
37+
module_test(Py3status)

pyproject.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[tool.poetry]
2+
name = "http_monitor"
3+
version = "0.1.0"
4+
description = ""
5+
authors = ["mcgillij <mcgillivray.jason@gmail.com>"]
6+
license = "MIT"
7+
8+
[tool.poetry.dependencies]
9+
python = "^3.9"
10+
py3status = "^3.31"
11+
12+
[tool.poetry.dev-dependencies]
13+
14+
[build-system]
15+
requires = ["poetry-core>=1.0.0"]
16+
build-backend = "poetry.core.masonry.api"

0 commit comments

Comments
 (0)