菜单
Grafana Cloud

PRTG 对 Grafana OnCall 的集成

注意

此集成仅在 Grafana Cloud 上可用。

此 PRTG 集成处理从 PRTG Webhook 发送的票证事件。通过可自定义的警报模板,集成提供分组、自动确认和自动解决逻辑。

配置 Grafana OnCall 以接收来自 PRTG 的警报

  1. 集成 选项卡中,点击 + 新集成
  2. 从可用集成列表中选择 PRTG
  3. 输入集成名称和描述,点击 创建
  4. 将打开一个新的页面,显示集成详细信息。从 HTTP 端点 部分复制 OnCall 集成 URL

配置 PRTG 以向 Grafana OnCall 发送警报

PRTG 可以使用脚本将警报发送到 Grafana OnCall。请使用以下格式

正文字段格式

plaintext
alert_uid [char][not required] - unique alert ID for grouping;
title [char][not required] - title;
image_url [char][not required] - url for image attached to alert;
state [char][not required] - could be "ok" or "alerting", helpful for auto-resolving;
link_to_upstream_details [char][not required] - link back to your monitoring system;
message [char][not required] - alert details;

ps1 脚本示例

ps1
# This script sends alerts from PRTG to Grafana OnCall
Param(
  [string]$sensorid,
  [string]$date,
  [string]$device,
  [string]$shortname,
  [string]$status,
  [string]$message,
  [string]$datetime,
  [string]$linksensor,
  [string]$url
)

# PRTG Server
$PRTGServer = "localhost:8080"
$PRTGUsername = "oncall"
$PRTGPasshash  = *****

#Directory for logging
$LogDirectory = "C:\temp\prtg-notifications-msteam.log"

#Acknowledgement Message for alerts ack'd via Teams
$ackmessage = "Problem has been acknowledged via OnCall."

# the acknowledgement URL
$ackURL = [string]::Format("{0}/api/acknowledgealarm.htm?id={1}&ackmsg={2}&username={3}&passhash={4}",
$PRTGServer,$sensorID,$ackmessage,$PRTGUsername,$PRTGPasshash);

# Autoresolve an alert in OnCall
if($status -eq "Up")
{ $state = "ok" }
ElseIf($status -match "now: Up")
{ $state = "ok" }
ElseIf($status -match "Up (was:")
{ $state = "ok" }
Else
{ $state = "alerting" }

$image_datetime = [datetime]::parse($datetime)
$sdate = $image_datetime.AddHours(-1).ToString("yyyy-MM-dd-HH-mm-ss")
$edate = $image_datetime.ToString("yyyy-MM-dd-HH-mm-ss")

$image_url = "$PRTGServer/chart.png?type=graph&graphid=-1&avg=0&width=1000&height=400
&username=$PRTGUsername&passhash=$PRTGPasshash&id=$sensorid&sdate=$sdate&edate=$edate"

$Body = @{
            "alert_uid"="$sensorid $date";
            "title"="$device $shortname $status at $datetime ";
            "image_url"=$image_url;
            "state"=$state;
            "link_to_upstream_details"="$linksensor";
            "message"="$message";
            "ack_url_get"="$ackURL"
} | ConvertTo-Json
$Body

try
{ Invoke-RestMethod -uri $url -Method Post -body $Body -ContentType 'application/json; charset=utf-8'; exit 0; }
Catch
{
    $ErrorMessage = $_.Exception.Message
    (Get-Date).ToString() +" - "+ $ErrorMessage | Out-File -FilePath $LogDirectory -Append
    exit 2;
}