alert

package
v1.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 31, 2022 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

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.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

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.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

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.

Copyright © 2021 NAME HERE <EMAIL ADDRESS>

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.

Index

Constants

This section is empty.

Variables

View Source
var AlertCmd = &cobra.Command{
	Use:     "alert",
	Aliases: []string{"alerts"},
	Run: func(cmd *cobra.Command, args []string) {
		cmd.Help()
		os.Exit(0)
	},
}

alertCmd represents the alert command

View Source
var GroupFilename, RuleState, GroupName string
View Source
var GroupSubCmd = &cobra.Command{
	Use:     "group",
	Aliases: []string{"groups"},
	Run: func(cmd *cobra.Command, args []string) {
		resourcesNames := args
		monitoringExist, _ := helpers.Exists(vars.MustGatherRootPath + "/monitoring")
		if !monitoringExist {
			fmt.Println("Path '" + vars.MustGatherRootPath + "/monitoring' does not exist.")
			os.Exit(1)
		}
		alertsFilePath := vars.MustGatherRootPath + "/monitoring/alerts.json"
		alertsFilePathExist, _ := helpers.Exists(alertsFilePath)
		if !alertsFilePathExist {
			alertsFilePath = vars.MustGatherRootPath + "/monitoring/prometheus/rules.json"
			alertsFilePathExist, _ := helpers.Exists(alertsFilePath)
			if !alertsFilePathExist {
				fmt.Println("Prometheus rules not found in must-gather.")
				os.Exit(1)
			}
		}
		GetAlertGroups(resourcesNames, vars.OutputStringVar, GroupFilename, alertsFilePath)
	},
}
View Source
var RuleSubCmd = &cobra.Command{
	Use:     "rule",
	Aliases: []string{"rules"},
	Run: func(cmd *cobra.Command, args []string) {
		resourcesNames := args
		monitoringExist, _ := helpers.Exists(vars.MustGatherRootPath + "/monitoring")
		if !monitoringExist {
			fmt.Println("Path '" + vars.MustGatherRootPath + "/monitoring' does not exist.")
			os.Exit(1)
		}
		alertsFilePath := vars.MustGatherRootPath + "/monitoring/alerts.json"
		alertsFilePathExist, _ := helpers.Exists(alertsFilePath)
		if !alertsFilePathExist {
			alertsFilePath = vars.MustGatherRootPath + "/monitoring/prometheus/rules.json"
			alertsFilePathExist, _ := helpers.Exists(alertsFilePath)
			if !alertsFilePathExist {
				fmt.Println("Prometheus rules not found in must-gather.")
				os.Exit(1)
			}
		}
		GetAlertRules(resourcesNames, vars.OutputStringVar, GroupName, RuleState, alertsFilePath)
	},
}

Functions

func GetAlertGroups

func GetAlertGroups(resourcesNames []string, outputFlag string, groupFile string, alertsFilePath string)

func GetAlertRules

func GetAlertRules(resourcesNames []string, outputFlag string, groupsNames string, rulesStates string, alertsFilePath string)

Types

type AlertingRule

type AlertingRule struct {
	// State can be "pending", "firing", "inactive".
	State          string       `json:"state"`
	Name           string       `json:"name"`
	Query          string       `json:"query"`
	Duration       float64      `json:"duration"`
	Labels         Labels       `json:"labels"`
	Annotations    Labels       `json:"annotations"`
	Alerts         []*PromAlert `json:"alerts"`
	Health         RuleHealth   `json:"health"`
	LastError      string       `json:"lastError,omitempty"`
	EvaluationTime float64      `json:"evaluationTime"`
	LastEvaluation time.Time    `json:"lastEvaluation"`
	// Type of an alertingRule is always "alerting".
	Type string `json:"type"`
}

type FilteredRulesList

type FilteredRulesList struct {
	Data []Rule `json:"data"`
}

type Label

type Label struct {
	Name, Value string
}

type Labels

type Labels []Label

Labels is a sorted set of labels. Order has to be guaranteed upon instantiation.

type PromAlert

type PromAlert struct {
	Labels      Labels     `json:"labels"`
	Annotations Labels     `json:"annotations"`
	State       string     `json:"state"`
	ActiveAt    *time.Time `json:"activeAt,omitempty"`
	Value       string     `json:"value"`
}

type Rule

type Rule map[string]interface{}

type RuleGroup

type RuleGroup struct {
	Name string `json:"name"`
	File string `json:"file"`
	// In order to preserve rule ordering, while exposing type (alerting or recording)
	// specific properties, both alerting and recording rules are exposed in the
	// same array.
	Rules          []Rule    `json:"rules"`
	Interval       float64   `json:"interval"`
	Limit          int       `json:"limit"`
	EvaluationTime float64   `json:"evaluationTime"`
	LastEvaluation time.Time `json:"lastEvaluation"`
}

type RuleHealth

type RuleHealth string
const (
	HealthUnknown RuleHealth = "unknown"
	HealthGood    RuleHealth = "ok"
	HealthBad     RuleHealth = "err"
)

The possible health states of a rule based on the last execution.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL