-
Notifications
You must be signed in to change notification settings - Fork 463
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
Backend: implement alerting query #847
Backend: implement alerting query #847
Conversation
This reverts commit e0ffdff.
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.
At the first glance I see plugin doesn't return any data. I think it might be related to authentication. I'll try to figure it out.
pkg/models.go
Outdated
RealHosts bool `json:"real_hosts,omitempty"` | ||
|
||
// History GET | ||
History int `json:"history,omitempty,string"` |
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.
This won't work for history type 0
since integer 0
will be treated as an empty value. Use *int
instead.
History int `json:"history,omitempty,string"` | |
History *int `json:"history,string,omitempty"` |
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.
https://github.com/alexanderzobnin/grafana-zabbix/pull/847/files#diff-2cb344693fe3302e52c776fc8f6e3964R64 newDs := b.newZabbixDatasource()
b.datasourceCache.Set(dsInfoHash, newDs)
return b.newZabbixDatasource() |
pkg/zabbix_api.go
Outdated
if useTrend { | ||
response, err = ds.ZabbixRequest(ctx, tsdbReq.GetDatasource(), "trend.get", params) | ||
} else { | ||
params.History = k |
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.
History should be a pointer in order to prevent it to be omitted.
params.History = k | |
params.History = &k |
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.
appFilter := firstQuery.GetPath("application", "filter").MustString() | ||
itemFilter := firstQuery.GetPath("item", "filter").MustString() | ||
|
||
items, err := ds.getItems(ctx, tsdbReq.GetDatasource(), groupFilter, hostFilter, appFilter, itemFilter, "num") |
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.
getItems()
return empty list in my case. Looks like something goes wrong there.
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.
We're able to get items with specific queries. Could this be related to the Regex filter not working properly?
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.
If any regex was used then it would never return any items, with the latest change that should be resolved.
pkg/zabbix_api.go
Outdated
filteredItems := zabbix.Items{} | ||
for _, item := range items { | ||
if item.Status == "0" { | ||
matched, err := regexp.MatchString(itemFilter, item.Name) |
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.
This filter doesn't work. There're 2 cases in filters:
- Filter is a group/host/app/item name. So exact string comparison should be used.
- Filter is a regex (wrapped in
/
, like/CPU (.*) time/
). Since go regex should be compiled without first and last/
, it should be removed beforeMatchString()
execution.
function findByFilter(list, filter) {
if (utils.isRegex(filter)) {
return filterByRegex(list, filter);
} else {
return findByName(list, filter);
}
}
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.
We're working on the Regex filter now. I pointed this out earlier but we set it aside to get a PR out before the holidays. The trickiest bit right now is handling flags, which a few are currently supported but the syntax for that is different in Go.
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.
I have updated the Regex filter the following way:
- Check if the filter is a regex
- If it is a regex then check for any flags, separate them and covert them to go regex format
- If it is not regex do a regular string comparison
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.
Also b6c2116
Added unit tests and added a check for supported flags.
Caching new datasource instances: 74b97b6 |
pkg/zabbix_api.go
Outdated
@@ -429,14 +440,20 @@ func (ds *ZabbixDatasource) getHosts(ctx context.Context, dsInfo *datasource.Dat | |||
if err != nil { | |||
return nil, err | |||
} | |||
isRegex, hostFilter := parseFilter(hostFilter) | |||
re := regexp.MustCompile(hostFilter) |
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.
Don't use MustCompile
if the filter isn't meant to be a regex. If it's not a valid pattern, it will panic.
Also perhaps we want to use something that returns an error when it fails to compile so we can surface that to the user as a user error.
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.
Updated, 04b1b2a
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.
b6c2116
Cleaned it up a bit and added unit tests for parseFilter
…h/grafana-zabbix into alerting-new-historymetrics
Issue #801
Implemented alerting query issue to get data from Zabbix and parse the query by fetching groups, hosts, apps, and items.