Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
alertmanager_status
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
varac-projects
alertmanager_status
Commits
a2ceafc3
Unverified
Commit
a2ceafc3
authored
2 years ago
by
Varac
Browse files
Options
Downloads
Patches
Plain Diff
Bring back query_alertmanager.py
parent
bd2c740c
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
README.md
+23
-22
23 additions, 22 deletions
README.md
alertmanager_status.py
+1
-1
1 addition, 1 deletion
alertmanager_status.py
query_alertmanager.py
+70
-0
70 additions, 0 deletions
query_alertmanager.py
with
94 additions
and
23 deletions
README.md
+
23
−
22
View file @
a2ceafc3
...
@@ -9,29 +9,19 @@ based on [libappindicator](https://launchpad.net/libappindicator). I don't use
...
@@ -9,29 +9,19 @@ based on [libappindicator](https://launchpad.net/libappindicator). I don't use
it anymore and it doesn't work in the current state, although it might be
it anymore and it doesn't work in the current state, although it might be
easy to get it working again.
easy to get it working again.

## Todo
## Todo
*
Red icon on
`Can't connect`
*
Reduce duplicator code in
`query_alertmanager.py`
and
`alertmanager_status.py`
*
trigger refresh
*
notifications
*
flash icon / paint red
*
Show alert details in menu
*
example systemd service
## Install
## Install
Install dependencies
(
`libffi7`
is needed by
`pygobject`
)
:
Install dependencies:
sudo apt install gir1.2-appindicator3-0.1 libffi7
pip install -r requirements.txt
pip install -r requirements.txt
## Configuration
## Configuration
Config file example (
`~/.config/
indicator_
alertmanager/config.yml`
):
Config file example (
`~/.config/alertmanager
_status
/config.yml`
):
```yaml
```yaml
---
---
...
@@ -42,21 +32,32 @@ password: 123
...
@@ -42,21 +32,32 @@ password: 123
```
```
##
U
sage
##
Standalone u
sage
Start the indicator:
Start the indicator:
```
bash
```
bash
./
indicator_
alertmanager.py
./alertmanager
_status
.py
```
```
## query_alertmanager.py
## Waybar integration
Use as a library for indicator_alertmanager, but can also get used from command
```
json
line, see:
"custom/alertmanager": {
"return-type": "json",
```
bash
"interval": 60,
query_alertmanager.py -h
"format": "Alerts: {} {icon}",
//"exec-if": "exit 0", // always run; consider advanced run conditions
"format-icons": {
"firing": "🔥",
"snafu": "🟢",
"error": "🚫"
},
"exec": "/bin/bash -c 'cd /home/varac/projects/monitoring/indicator_alertmanager/ && . ./.direnv/
*
/bin/activate && ./alertmanager_status.py'",
"signal": 21,
"on-click": "pkill -RTMIN+21 waybar",
"on-click-right": "xdg-open https://alertmanager.oas.varac.net",
}
```
```
## Similar projects
## Similar projects
...
...
This diff is collapsed.
Click to expand it.
alertmanager_status.py
+
1
−
1
View file @
a2ceafc3
...
@@ -41,7 +41,7 @@ def show_alerts(opts):
...
@@ -41,7 +41,7 @@ def show_alerts(opts):
@plac.opt
(
'
configpath
'
,
"
Path to alertmanager config
"
,
type
=
Path
)
@plac.opt
(
'
configpath
'
,
"
Path to alertmanager config
"
,
type
=
Path
)
@plac.opt
(
'
mode
'
,
"
Mode: wayland or indicator (not working)
"
,
type
=
str
)
@plac.opt
(
'
mode
'
,
"
Mode: wayland or indicator (not working)
"
,
type
=
str
)
@plac.flg
(
'
debug
'
,
"
Enable debug mode
"
)
@plac.flg
(
'
debug
'
,
"
Enable debug mode
"
)
def
main
(
configpath
=
'
~/.config/
indicator_
alertmanager/config.yml
'
,
def
main
(
configpath
=
'
~/.config/alertmanager
_status
/config.yml
'
,
mode
=
"
wayland
"
):
mode
=
"
wayland
"
):
"""
Main function.
"""
"""
Main function.
"""
...
...
This diff is collapsed.
Click to expand it.
query_alertmanager.py
0 → 100755
+
70
−
0
View file @
a2ceafc3
#!/usr/bin/env python3
"""
Queries alertmanager for alerts, outputs json.
Can be also used as cli application.
Usage:
./query_alertmananger.py -h
"""
import
json
import
plac
import
requests
from
alertmanager
import
AlertManager
def
get_alerts
(
url
,
password
,
port
=
443
,
user
=
'
admin
'
):
req
=
requests
.
Session
()
req
.
auth
=
(
user
,
password
)
AM
=
AlertManager
(
host
=
url
,
port
=
port
,
req_obj
=
req
)
count
=
0
alerts
=
[]
state
=
"
unknown
"
try
:
alerts_raw
=
AM
.
get_alerts
()
for
alert
in
alerts_raw
:
name
=
alert
[
'
labels
'
][
'
alertname
'
]
severity
=
alert
[
'
labels
'
][
'
severity
'
]
instance
=
alert
[
'
labels
'
][
'
instance
'
]
alert_state
=
alert
[
'
status
'
][
'
state
'
]
release_name
=
alert
[
'
labels
'
][
'
release_name
'
]
if
severity
!=
"
none
"
and
alert_state
!=
"
suppressed
"
:
count
+=
1
alert_text
=
f
'
{
name
}
:
{
instance
}
,
{
release_name
}
(
{
severity
}
)
'
alerts
.
append
(
alert_text
)
if
count
>
2
:
state
=
"
critical
"
elif
count
>
0
:
state
=
"
warning
"
elif
count
==
0
:
state
=
"
ok
"
summary
=
f
'
{
count
}
alerts
'
except
:
summary
=
"
Cant connect
"
state
=
"
warning
"
return_data
=
{
'
summary
'
:
summary
,
'
alerts
'
:
alerts
,
'
state
'
:
state
,
'
count
'
:
count
}
return
return_data
@plac.opt
(
'
url
'
,
"
URL of alertmanager instance
"
,
type
=
str
,
abbrev
=
'
U
'
)
@plac.opt
(
'
port
'
,
"
Port of alertmanager instance
"
,
type
=
int
,
abbrev
=
'
P
'
)
@plac.opt
(
'
user
'
,
"
User name
"
,
type
=
str
)
@plac.opt
(
'
password
'
,
"
Password
"
,
type
=
str
)
def
main
(
url
,
password
,
port
=
443
,
user
=
'
admin
'
):
"""
Main function.
"""
alerts
=
get_alerts
(
url
=
url
,
password
=
password
,
port
=
port
,
user
=
user
)
print
(
json
.
dumps
(
alerts
))
if
__name__
==
'
__main__
'
:
plac
.
call
(
main
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment