-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Prometheus alert manager exporter #437
Changes from all commits
5e63e93
bf4c994
42d66b0
69e5d8b
495b31a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright 2020 The SODA Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
import requests | ||
from oslo_config import cfg | ||
from oslo_log import log | ||
|
||
LOG = log.getLogger(__name__) | ||
CONF = cfg.CONF | ||
alert_mngr_opts = [ | ||
|
||
cfg.StrOpt('alert_manager_host', default='localhost', | ||
help='The prometheus alert manager host'), | ||
cfg.StrOpt('alert_manager_port', default='9093', | ||
help='The prometheus alert manager port'), | ||
] | ||
|
||
CONF.register_opts(alert_mngr_opts, "PROMETHEUS_ALERT_MANAGER_EXPORTER") | ||
alert_cfg = CONF.PROMETHEUS_ALERT_MANAGER_EXPORTER | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason to make alert_cfg global ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Values are read once and never changed after that.. No other specific reason, all conf read in delfin is global to file scope AFIK.
wisererik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
class PrometheusAlertExporter(object): | ||
alerts = [] | ||
model_key = ['alert_id', 'alert_name', 'sequence_number', 'category', | ||
'severity', 'type', 'location', 'recovery_advice', | ||
'storage_id', 'storage_name', 'vendor', | ||
'model', 'serial_number', 'occur_time'] | ||
|
||
def push_prometheus_alert(self, alerts): | ||
|
||
host = alert_cfg.alert_manager_host | ||
port = alert_cfg.alert_manager_port | ||
for alert in alerts: | ||
dict = {} | ||
dict["labels"] = {} | ||
dict["annotations"] = {} | ||
for key in self.model_key: | ||
dict["labels"][key] = str(alert.get(key)) | ||
|
||
dict["annotations"]["summary"] = alert.get("description") | ||
|
||
self.alerts.append(dict) | ||
try: | ||
response = requests.post('http://' + host + ":" + port + | ||
'/api/v1/alerts', | ||
json=self.alerts) | ||
if response.status_code != 200: | ||
LOG.error("POST request failed for alert %s ", | ||
alert.get('alert_id')) | ||
except Exception: | ||
LOG.error("Exporting alert to alert manager has been failed " | ||
"for alert %s ", alert.get('alert_id')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make some fields random ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, alert id and occur_time is random