Skip to content
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

id in the variable _GRAFANA_URL_PATH_OBTAIN_METRICS is incorrect #11

Open
vmironenko opened this issue Oct 6, 2015 · 0 comments
Open

Comments

@vmironenko
Copy link

When I ran grafanaAlerts command in console, I received error:


  File "/usr/bin/grafanaalerts", line 11, in 
    sys.exit(main())
  File "/usr/lib/python2.6/site-packages/grafana_alerts/__init__.py", line 12, in main
    return the_launcher.launch()
  File "/usr/lib/python2.6/site-packages/grafana_alerts/launcher.py", line 16, in launch
    alert_checker.check()
  File "/usr/lib/python2.6/site-packages/grafana_alerts/alerting.py", line 50, in check
    alert_checker.check()
  File "/usr/lib/python2.6/site-packages/grafana_alerts/alerting.py", line 103, in check
    contents = urllib2.urlopen(request).read()
  File "/usr/lib64/python2.6/urllib2.py", line 126, in urlopen
    return _opener.open(url, data, timeout)
  File "/usr/lib64/python2.6/urllib2.py", line 397, in open
    response = meth(req, response)
  File "/usr/lib64/python2.6/urllib2.py", line 510, in http_response
    'http', request, response, code, msg, hdrs)
  File "/usr/lib64/python2.6/urllib2.py", line 435, in error
    return self._call_chain(*args)
  File "/usr/lib64/python2.6/urllib2.py", line 369, in _call_chain
    result = func(*args)
  File "/usr/lib64/python2.6/urllib2.py", line 518, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
urllib2.HTTPError: HTTP Error 500: Internal Server Error

It's because there is an incorrect use the path http://my_grafana/api/datasources/proxy/1/... there.
I ran curl "http://my_grafana/api/datasources/" and received a answer:

[{"id":4,"orgId":1,"name":"cyanite","type":"graphite","access":"proxy","url":"http://10.1.41.44","password":"","user":"","database":"","basicAuth":false,"basicAuthUser":"","basicAuthPassword":"","isDefault":false,"jsonData":null},{"id":7,"orgId":1,"name":"cyanite_cluster","type":"graphite","access":"proxy","url":"http://10.16.41.183","password":"","user":"","database":"","basicAuth":false,"basicAuthUser":"","basicAuthPassword":"","isDefault":true,"jsonData":null},{"id":3,"orgId":1,"name":"influxDB","type":"influxdb","access":"proxy","url":"http://10.1.41.44:8086","password":"q1q1q1","user":"grafana","database":"test","basicAuth":false,"basicAuthUser":"","basicAuthPassword":"","isDefault":false,"jsonData":null}]

I saw I have few configurations in grafana but I was interested the configuration with id=7. Then I've updated the variable _GRAFANA_URL_PATH_OBTAIN_METRICS = 'api/datasources/proxy/7/render' in the alerting.py file

After it I got a new error:


  File "/usr/bin/grafanaalerts", line 11, in 
    sys.exit(main())
  File "/usr/lib/python2.6/site-packages/grafana_alerts/__init__.py", line 12, in main
    return the_launcher.launch()
  File "/usr/lib/python2.6/site-packages/grafana_alerts/launcher.py", line 16, in launch
    alert_checker.check()
  File "/usr/lib/python2.6/site-packages/grafana_alerts/alerting.py", line 53, in check
    self.alert_reporter.report(reported_alerts)
  File "/usr/lib/python2.6/site-packages/grafana_alerts/reporting.py", line 70, in report
    alerts_to_send_map = self._group_by(diff_report, 'alert_destination')
  File "/usr/lib/python2.6/site-packages/grafana_alerts/reporting.py", line 161, in _group_by
    if key is None:
UnboundLocalError: local variable 'key' referenced before assignment

Then I've added a line: key='' at the beginning of the def _group_by() function in reporting.py.
After it I received a next error:


  File "/usr/bin/grafanaalerts", line 11, in 
    sys.exit(main())
  File "/usr/lib/python2.6/site-packages/grafana_alerts/__init__.py", line 12, in main
    return the_launcher.launch()
  File "/usr/lib/python2.6/site-packages/grafana_alerts/launcher.py", line 16, in launch
    alert_checker.check()
  File "/usr/lib/python2.6/site-packages/grafana_alerts/alerting.py", line 53, in check
    self.alert_reporter.report(reported_alerts)
  File "/usr/lib/python2.6/site-packages/grafana_alerts/reporting.py", line 71, in report
    self._send_alerts_if_any(alerts_to_send_map)
  File "/usr/lib/python2.6/site-packages/grafana_alerts/reporting.py", line 175, in _send_alerts_if_any
    if not self._is_something_to_report(alert_event_list):
  File "/usr/lib/python2.6/site-packages/grafana_alerts/reporting.py", line 302, in _is_something_to_report
    if alert_event['current'].current_alert_condition_status['name'] != 'normal':
TypeError: 'NoneType' object is unsubscriptable
 

Then I've updated _is_something_to_report(self, alert_event_list) function as below:


    def _is_something_to_report(self, alert_event_list):
        """Return True if the alert should be sent."""
        # TODO externalize this condition.
        for alert_event in alert_event_list:
            if alert_event['current'] is None:
                continue
            if alert_event['current'].current_alert_condition_status is None:
                continue
            if alert_event['current'].current_alert_condition_status['name'] != 'normal':
                return True
            if alert_event['old'] is None:
                continue
            if alert_event['old'].current_alert_condition_status['name'] is None:
                continue
            if alert_event['old'].current_alert_condition_status['name'] != 'normal':
                return True
        return False

After these changes I get no more errors but I'm not sure I did it correctly
I think that id in variable _GRAFANA_URL_PATH_OBTAIN_METRICS should be calculated automatically at program start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant