Skip to content

Commit

Permalink
Filter alerts - Add ThrottleTimeSeconds and ThrottleField (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
fjerlov-cs committed Jul 4, 2024
1 parent 517aa79 commit b70d822
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 65 deletions.
82 changes: 45 additions & 37 deletions api/filter-alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import (
)

type FilterAlert struct {
ID string `graphql:"id" yaml:"-" json:"id"`
Name string `graphql:"name" yaml:"name" json:"name"`
Description string `graphql:"description" yaml:"description,omitempty" json:"description,omitempty"`
QueryString string `graphql:"queryString" yaml:"queryString" json:"queryString"`
ActionNames []string `graphql:"actionNames" yaml:"actionNames" json:"actionNames"`
Labels []string `graphql:"labels" yaml:"labels" json:"labels"`
Enabled bool `graphql:"enabled" yaml:"enabled" json:"enabled"`
QueryOwnershipType string `graphql:"queryOwnership" yaml:"queryOwnershipType" json:"queryOwnershipType"`
RunAsUserID string `graphql:"runAsUserId" yaml:"runAsUserId,omitempty" json:"runAsUserId,omitempty"`
ID string `graphql:"id" yaml:"-" json:"id"`
Name string `graphql:"name" yaml:"name" json:"name"`
Description string `graphql:"description" yaml:"description,omitempty" json:"description,omitempty"`
QueryString string `graphql:"queryString" yaml:"queryString" json:"queryString"`
ActionNames []string `graphql:"actionNames" yaml:"actionNames" json:"actionNames"`
Labels []string `graphql:"labels" yaml:"labels" json:"labels"`
Enabled bool `graphql:"enabled" yaml:"enabled" json:"enabled"`
QueryOwnershipType string `graphql:"queryOwnership" yaml:"queryOwnershipType" json:"queryOwnershipType"`
ThrottleTimeSeconds int `graphql:"throttleTimeSeconds" yaml:"throttleTimeSeconds,omitempty" json:"throttleTimeSeconds,omitempty"`
ThrottleField string `graphql:"throttleField" yaml:"throttleField,omitempty" json:"throttleField"`
RunAsUserID string `graphql:"runAsUserId" yaml:"runAsUserId,omitempty" json:"runAsUserId,omitempty"`
}

type FilterAlerts struct {
Expand Down Expand Up @@ -72,16 +74,18 @@ func (fa *FilterAlerts) Update(viewName string, updatedFilterAlert *FilterAlert)
}

updateAlert := humiographql.UpdateFilterAlert{
ViewName: humiographql.RepoOrViewName(viewName),
ID: graphql.String(updatedFilterAlert.ID),
Name: graphql.String(updatedFilterAlert.Name),
Description: graphql.String(updatedFilterAlert.Description),
QueryString: graphql.String(updatedFilterAlert.QueryString),
ActionIdsOrNames: actionNames,
Labels: labels,
Enabled: graphql.Boolean(updatedFilterAlert.Enabled),
RunAsUserID: graphql.String(updatedFilterAlert.RunAsUserID),
QueryOwnershipType: humiographql.QueryOwnershipType(updatedFilterAlert.QueryOwnershipType),
ViewName: humiographql.RepoOrViewName(viewName),
ID: graphql.String(updatedFilterAlert.ID),
Name: graphql.String(updatedFilterAlert.Name),
Description: graphql.String(updatedFilterAlert.Description),
QueryString: graphql.String(updatedFilterAlert.QueryString),
ActionIdsOrNames: actionNames,
Labels: labels,
Enabled: graphql.Boolean(updatedFilterAlert.Enabled),
RunAsUserID: graphql.String(updatedFilterAlert.RunAsUserID),
ThrottleTimeSeconds: humiographql.Long(updatedFilterAlert.ThrottleTimeSeconds),
ThrottleField: graphql.String(updatedFilterAlert.ThrottleField),
QueryOwnershipType: humiographql.QueryOwnershipType(updatedFilterAlert.QueryOwnershipType),
}

variables := map[string]any{
Expand Down Expand Up @@ -118,15 +122,17 @@ func (fa *FilterAlerts) Create(viewName string, newFilterAlert *FilterAlert) (*F
}

createFilterAlert := humiographql.CreateFilterAlert{
ViewName: humiographql.RepoOrViewName(viewName),
Name: graphql.String(newFilterAlert.Name),
Description: graphql.String(newFilterAlert.Description),
QueryString: graphql.String(newFilterAlert.QueryString),
ActionIdsOrNames: actionNames,
Labels: labels,
Enabled: graphql.Boolean(newFilterAlert.Enabled),
RunAsUserID: graphql.String(newFilterAlert.RunAsUserID),
QueryOwnershipType: humiographql.QueryOwnershipType(newFilterAlert.QueryOwnershipType),
ViewName: humiographql.RepoOrViewName(viewName),
Name: graphql.String(newFilterAlert.Name),
Description: graphql.String(newFilterAlert.Description),
QueryString: graphql.String(newFilterAlert.QueryString),
ActionIdsOrNames: actionNames,
Labels: labels,
Enabled: graphql.Boolean(newFilterAlert.Enabled),
ThrottleTimeSeconds: humiographql.Long(newFilterAlert.ThrottleTimeSeconds),
ThrottleField: graphql.String(newFilterAlert.ThrottleField),
RunAsUserID: graphql.String(newFilterAlert.RunAsUserID),
QueryOwnershipType: humiographql.QueryOwnershipType(newFilterAlert.QueryOwnershipType),
}

variables := map[string]any{
Expand Down Expand Up @@ -209,14 +215,16 @@ func mapHumioGraphqlFilterAlertToFilterAlert(input humiographql.FilterAlert) Fil
}

return FilterAlert{
ID: string(input.ID),
Name: string(input.Name),
Description: string(input.Description),
QueryString: string(input.QueryString),
ActionNames: actionNames,
Labels: labels,
Enabled: bool(input.Enabled),
QueryOwnershipType: queryOwnershipType,
RunAsUserID: runAsUserID,
ID: string(input.ID),
Name: string(input.Name),
Description: string(input.Description),
QueryString: string(input.QueryString),
ActionNames: actionNames,
Labels: labels,
Enabled: bool(input.Enabled),
ThrottleTimeSeconds: int(input.ThrottleTimeSeconds),
ThrottleField: string(input.ThrottleField),
QueryOwnershipType: queryOwnershipType,
RunAsUserID: runAsUserID,
}
}
60 changes: 33 additions & 27 deletions api/internal/humiographql/filter-alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,47 @@ import (
)

type FilterAlert struct {
ID graphql.String `graphql:"id"`
Name graphql.String `graphql:"name"`
Description graphql.String `graphql:"description"`
QueryString graphql.String `graphql:"queryString"`
Actions []Action `graphql:"actions"`
Labels []graphql.String `graphql:"labels"`
Enabled graphql.Boolean `graphql:"enabled"`
QueryOwnership QueryOwnership `graphql:"queryOwnership"`
ID graphql.String `graphql:"id"`
Name graphql.String `graphql:"name"`
Description graphql.String `graphql:"description"`
QueryString graphql.String `graphql:"queryString"`
Actions []Action `graphql:"actions"`
Labels []graphql.String `graphql:"labels"`
Enabled graphql.Boolean `graphql:"enabled"`
ThrottleTimeSeconds Long `graphql:"throttleTimeSeconds"`
ThrottleField graphql.String `graphql:"throttleField"`
QueryOwnership QueryOwnership `graphql:"queryOwnership"`
}

type Action struct {
Name graphql.String `graphql:"name"`
}

type CreateFilterAlert struct {
ViewName RepoOrViewName `json:"viewName"`
Name graphql.String `json:"name"`
Description graphql.String `json:"description,omitempty"`
QueryString graphql.String `json:"queryString"`
ActionIdsOrNames []graphql.String `json:"actionIdsOrNames"`
Labels []graphql.String `json:"labels"`
Enabled graphql.Boolean `json:"enabled"`
RunAsUserID graphql.String `json:"runAsUserId,omitempty"`
QueryOwnershipType QueryOwnershipType `json:"queryOwnershipType"`
ViewName RepoOrViewName `json:"viewName"`
Name graphql.String `json:"name"`
Description graphql.String `json:"description,omitempty"`
QueryString graphql.String `json:"queryString"`
ActionIdsOrNames []graphql.String `json:"actionIdsOrNames"`
Labels []graphql.String `json:"labels"`
Enabled graphql.Boolean `json:"enabled"`
ThrottleTimeSeconds Long `json:"throttleTimeSeconds"`
ThrottleField graphql.String `json:"throttleField"`
RunAsUserID graphql.String `json:"runAsUserId,omitempty"`
QueryOwnershipType QueryOwnershipType `json:"queryOwnershipType"`
}

type UpdateFilterAlert struct {
ViewName RepoOrViewName `json:"viewName"`
ID graphql.String `json:"id"`
Name graphql.String `json:"name"`
Description graphql.String `json:"description,omitempty"`
QueryString graphql.String `json:"queryString"`
ActionIdsOrNames []graphql.String `json:"actionIdsOrNames"`
Labels []graphql.String `json:"labels"`
Enabled graphql.Boolean `json:"enabled"`
RunAsUserID graphql.String `json:"runAsUserId,omitempty"`
QueryOwnershipType QueryOwnershipType `json:"queryOwnershipType"`
ViewName RepoOrViewName `json:"viewName"`
ID graphql.String `json:"id"`
Name graphql.String `json:"name"`
Description graphql.String `json:"description,omitempty"`
QueryString graphql.String `json:"queryString"`
ActionIdsOrNames []graphql.String `json:"actionIdsOrNames"`
Labels []graphql.String `json:"labels"`
Enabled graphql.Boolean `json:"enabled"`
ThrottleTimeSeconds Long `json:"throttleTimeSeconds"`
ThrottleField graphql.String `json:"throttleField"`
RunAsUserID graphql.String `json:"runAsUserId,omitempty"`
QueryOwnershipType QueryOwnershipType `json:"queryOwnershipType"`
}
4 changes: 3 additions & 1 deletion cmd/humioctl/filter_alerts_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ func newFilterAlertsListCmd() *cobra.Command {
format.String(filterAlert.Description),
format.String(strings.Join(filterAlert.ActionNames, ", ")),
format.String(strings.Join(filterAlert.Labels, ", ")),
format.Int(filterAlert.ThrottleTimeSeconds),
format.String(filterAlert.ThrottleField),
format.String(filterAlert.RunAsUserID),
format.String(filterAlert.QueryOwnershipType),
}
}

printOverviewTable(cmd, []string{"ID", "Name", "Enabled", "Description", "Actions", "Labels", "Run As User ID", "Query Ownership Type"}, rows)
printOverviewTable(cmd, []string{"ID", "Name", "Enabled", "Description", "Actions", "Labels", "Throttle Time Seconds", "Throttle Field", "Run As User ID", "Query Ownership Type"}, rows)
},
}

Expand Down
2 changes: 2 additions & 0 deletions cmd/humioctl/filter_alerts_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func newFilterAlertsShowCmd() *cobra.Command {
{format.String("Query String"), format.String(filterAlert.QueryString)},
{format.String("Labels"), format.String(strings.Join(filterAlert.Labels, ", "))},
{format.String("Actions"), format.String(strings.Join(filterAlert.ActionNames, ", "))},
{format.String("Throttle Time Seconds"), format.Int(filterAlert.ThrottleTimeSeconds)},
{format.String("Throttle Field"), format.String(filterAlert.ThrottleField)},
{format.String("Run As User ID"), format.String(filterAlert.RunAsUserID)},
{format.String("Query Ownership Type"), format.String(filterAlert.QueryOwnershipType)},
}
Expand Down

0 comments on commit b70d822

Please sign in to comment.