Commit 08508980 authored by Waqas Riaz's avatar Waqas Riaz

moved alert-config folder to master

parent 1a126e07
Pipeline #4179 failed with stages
in 1 second
{
/**
* Returns a new condition for Alert-Rule.
* Currently the only condition type that exists is a Query condition
*
* @name alert_condition.new
*
* @param evaluatorParams: Value of threshold
* @param evaluatorType: Type of threshold
* @param operatorType: Operator between conditions
* @param queryRefId: The letter defines what query to execute from the Metrics tab
* @param queryTimeStart: Begging of time range
* @param queryTimeEnd: End of time range
* @param reducerParams: Params of an aggregation function
* @param reducerType: Name of an aggregation function
*
* @return A json that represents a condition of alert
*/
new(
evaluatorParams=[],
evaluatorType='gt',
operatorType='and',
queryRefId='A',
queryTimeEnd=null,
queryTimeStart=null,
reducerParams=[],
reducerType='avg',
)::
{
evaluator: {
params: if std.type(evaluatorParams) == 'array' then evaluatorParams else [evaluatorParams],
type: evaluatorType,
},
operator: {
type: operatorType,
},
query: {
params: if queryTimeStart != null && queryTimeEnd != null then [queryRefId, queryTimeStart, queryTimeEnd] else [queryRefId] ,
},
reducer: {
params: if std.type(reducerParams) == 'array' then reducerParams else [reducerParams],
type: reducerType,
},
type: 'query',
},
}
{
/**
* Creates a contact point for an alert e.g email/slack.
*
* @name alert_contact.new
*
* @param uid: This is a unique identifier for the alert contact point. It is automatically generated by Grafana when the contact point is created.
* @param name: This is a user-defined name for the contact point. It is used to identify the contact point within Grafana.
* @param type: This field specifies the type of notification that will be sent, such as "email", "slack", "pagerduty", or "webhook".
* @param settings: This field contains the specific settings for the notification type, such as the email address to send the notification to or the webhook URL to post to. In the example you provided, the email address
* @param disableResolveMessage: This field controls whether or not a message should be sent when an alert condition is resolved. If set to false, a message will be sent when the alert condition is resolved.
* @return A json that represent alert contact point
*/
new(
uid,
name,
type,
address,
message=null,
singleEmail,
disableResolveMessage
)::
{
uid: uid,
name: name,
type: type,
settings: {
addresses: address,
[if message != null then 'message']: message,
singleEmail: singleEmail
},
disableResolveMessage: disableResolveMessage
},
}
JSONNET_PATH=grafonnet-lib \
jsonnet alert_contact_new.jsonnet > alert_contact_new.json
payload="$(jq . alert_contact_new.json)"
curl -X POST $BASIC_AUTH \
-H 'Content-Type: application/json' \
-d "${payload}" \
"http://admin:admin@localhost:3000/api/v1/provisioning/contact-points"
\ No newline at end of file
/**
* Creates a [Alert Rule Model]
* to be added in Grafana Alert Rule section
*
*
* @param refId: The unique reference ID for the query used in the alert rule. if the "refId" field is set to "B", which is used to reference this query in other parts of the alert rule.
* @param from: This field specifies the time range for the alert query, relative to the current time. In this case, the value of 600 means that the query should retrieve data from 600 seconds (10 minutes) ago to the current time.
* @param to: This field specifies the end time of the alert query relative to the current time. In this case, the value of 0 means that the end time of the query is the current time.
* @param datasourceUid: This field in the alert rule model specifies the unique identifier of the data source that the query for the alert is going to be executed on.
* @param editorMode: This field specifies the mode in which the query was created. In this case, it is "code" mode, which means that the query was written using the query language
* @param expr: Query expression to be run on the alert rule
* @param expression: This field specifies the name of the query that should be evaluated to determine if the alert condition is met. The query can be specified using either the query editor or the code editor in Grafana. The value of the "expression" field is "A", which means that the query with the reference ID "A" will be evaluated to determine if the alert condition is met.
* @param hide: Whether or not to show the result of the alert evaluation in the panel. In this example, it's set to false
* @param intervalMs: The interval at which to evaluate the alert. In this example, it's set to 1000 milliseconds.
* @param legendFormat: (optional) Set to `true` to hide the target from the panel.
* @param maxDataPoints: The maximum number of data points to retrieve for the query. In this example, it's set to 43200.
* @param range: This field specifies whether the query should include the time range in the query. If set to "true", the query will return data points within the specified time range.
* @param type: The type of the query. In this example, it's a "reduce" query.
* @param modelCondition: (optional) A list of conditions that must be met for the alert to trigger. In this example, there is only one condition that checks whether the value of the query result is greater than a certain threshold.
* @param reducer: The method used to reduce the time series data before performing the evaluation. In this example, it's the "count" method.
* @return A Alert Model to be added in Alert-Rule.
*/
{
new(
refId,
from,
to,
datasourceUid=null,
editorMode=null,
expr=null,
expression=null,
hide=null,
intervalMs,
legendFormat=null,
maxDataPoints,
range=null,
type=null,
modelCondition=null,
reducer=null
):: {
refId: refId,
relativeTimeRange: {
from: from,
to: to
},
datasourceUid: datasourceUid,
model: {
[if editorMode != null then 'editorMode']: editorMode,
[if expr != null then 'expr']: expr,
hide: hide,
intervalMs: intervalMs,
[if legendFormat != null then 'legendFormat']: legendFormat,
maxDataPoints: maxDataPoints,
[if modelCondition != null then 'conditions']: [modelCondition],
[if range != null then 'range']: range,
refId: refId,
[if reducer != null then 'reducer']: reducer,
[if type != null then 'type']: type,
[if expression != null then 'expression']: expression,
[if refId != 'A' then 'datasource']:
if refId != 'A' then
{
type: "__expr__",
uid: "__expr__"
}
else
null,
},
},
}
{
/**
* Creates Alert Rule for Grafana Dashboard|Panel
*
* @name alert_rule.new
*
* @param id: Unique identifier of Alert-Rule in numbers
* @param uid: Unique Identifier of Alert-Rule is Unique UID in String format
* @param orgID: organization id for Alert-Rule
* @param folderUID: Name of Folder available on Grafana server to make it attach with Alert-Rule
* @param ruleGroup: Name of the Group so Alert-Rule could be bundled in groups
* @param title: Unique title of Alert-Rule
* @param condition: Query or expression that determines whether the alert should be triggered.
* @param data: Array of sub-queries or conditions over query like (aggr. avg. threshold. Greater|Less) over above query
* @param updated: Reffers to the time when actually Alert-Rule was updated last time
* @param noDataState: This field specifies the state that the alert should be in if there is no data available to evaluate the condition. In this case, the value is NoData, indicating that the alert will enter the "no data" state
* @param execErrState: This field specifies the state that the alert should be in if there is an error while executing the condition. In this case, the value is Error, indicating that the alert will enter the "error" state.
* @param isPaused: This field specifies whether the alert is currently paused. In this case, the value is false, indicating that the alert is not paused and can trigger if the condition is met
* @method addAlertCondition(alert_data): Add sub conditions with refIds to the Alert-Rules
* @return A json that represents an Alert-Rule
*/
new(
id,
uid,
orgID,
folderUID,
ruleGroup,
title,
condition,
data=[],
updated,
noDataState,
execErrState,
isPaused,
dashboardUid=null,
panelId=null,
interval,
annotationDesc=null,
annotationSummary=null
)::
{
id: id,
uid: uid,
orgID: orgID,
folderUID: folderUID,
ruleGroup: ruleGroup,
title: title,
condition: condition,
updated: updated,
noDataState: noDataState,
execErrState: execErrState,
isPaused: isPaused,
[if dashboardUid != null then 'dashboardUid']:dashboardUid,
[if panelId != null then 'panelId']:panelId,
interval: interval,
annotations:{
description: annotationDesc,
summary: annotationSummary,
[if dashboardUid != null then '__dashboardUid__']: dashboardUid,
[if panelId != null then '__panelId__']: panelId
},
_data:: 0,
addAlertCondition(alert_data):: self {
// automatically ref id in added targets.
local data = super._data,
_data: data + 1,
data+: [alert_data],
}
},
}
\ No newline at end of file
JSONNET_PATH=grafonnet-lib \
jsonnet test_alert_new.jsonnet > test_alert_new.json
payload="$(jq . test_alert_new.json)"
curl -X POST $BASIC_AUTH \
-H 'Content-Type: application/json' \
-d "${payload}" \
"http://admin:admin@localhost:3000/api/v1/provisioning/alert-rules"
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment