mirror of
https://github.com/koichixD/uptime-kuma.git
synced 2026-09-03 15:00:31 +00:00
feat: add tags to teams notifications (#6939)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> Co-authored-by: Frank Elsinga <frank@elsinga.de>
This commit is contained in:
committed by
GitHub
parent
223dd92cc2
commit
bc90af1833
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"description": "RDAP bootstrap file for Domain Name System registrations",
|
||||
"publication": "2026-02-12T00:00:02Z",
|
||||
"publication": "2026-02-13T23:00:01Z",
|
||||
"services": [
|
||||
[["kg"], ["http://rdap.cctld.kg/"]],
|
||||
[["mg"], ["http://rdap.nic.mg/"]],
|
||||
@@ -652,7 +652,6 @@
|
||||
"weibo",
|
||||
"weir",
|
||||
"wine",
|
||||
"wolterskluwer",
|
||||
"works",
|
||||
"world",
|
||||
"wtf",
|
||||
|
||||
@@ -37,16 +37,31 @@ class Teams extends NotificationProvider {
|
||||
return "emphasis";
|
||||
};
|
||||
|
||||
/**
|
||||
* Format the tag for display. If the tag has a value, display as "name: value", otherwise just "name".
|
||||
* @param {object} tag The tag object to format
|
||||
* @returns {string} Formatted tag for display
|
||||
*/
|
||||
_tagDisplayText = (tag) => {
|
||||
if (tag.value === "" || tag.value === undefined || tag.value === null) {
|
||||
return tag.name;
|
||||
} else {
|
||||
return `${tag.name}: ${tag.value}`;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Generate payload for notification
|
||||
* @param {object} args Method arguments
|
||||
* @param {object} args.heartbeatJSON Heartbeat details
|
||||
* @param {string} args.monitorName Name of the monitor affected
|
||||
* @param {string} args.monitorUrl URL of the monitor affected
|
||||
* @param {object} args.monitorJSON Monitor details
|
||||
* @param {string} args.dashboardUrl URL of the dashboard affected
|
||||
* @param {boolean} args.enableTags Whether to include tags in the notification
|
||||
* @returns {object} Notification payload
|
||||
*/
|
||||
_notificationPayloadFactory = ({ heartbeatJSON, monitorName, monitorUrl, dashboardUrl }) => {
|
||||
_notificationPayloadFactory = ({ heartbeatJSON, monitorJSON, dashboardUrl, enableTags }) => {
|
||||
const monitorUrl = this.extractAddress(monitorJSON);
|
||||
const monitorName = monitorJSON?.name;
|
||||
const status = heartbeatJSON?.status;
|
||||
const facts = [];
|
||||
const actions = [];
|
||||
@@ -93,6 +108,82 @@ class Teams extends NotificationProvider {
|
||||
});
|
||||
}
|
||||
|
||||
const payloadBody = [
|
||||
{
|
||||
type: "Container",
|
||||
verticalContentAlignment: "Center",
|
||||
items: [
|
||||
{
|
||||
type: "ColumnSet",
|
||||
style: this._getStyle(status),
|
||||
columns: [
|
||||
{
|
||||
type: "Column",
|
||||
width: "auto",
|
||||
verticalContentAlignment: "Center",
|
||||
items: [
|
||||
{
|
||||
type: "Image",
|
||||
width: "32px",
|
||||
style: "Person",
|
||||
url: "https://raw.githubusercontent.com/louislam/uptime-kuma/master/public/icon.png",
|
||||
altText: "Uptime Kuma Logo",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "Column",
|
||||
width: "stretch",
|
||||
items: [
|
||||
{
|
||||
type: "TextBlock",
|
||||
size: "Medium",
|
||||
weight: "Bolder",
|
||||
text: `**${this._statusMessageFactory(status, monitorName, false)}**`,
|
||||
},
|
||||
{
|
||||
type: "TextBlock",
|
||||
size: "Small",
|
||||
weight: "Default",
|
||||
text: "Uptime Kuma Alert",
|
||||
isSubtle: true,
|
||||
spacing: "None",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "FactSet",
|
||||
separator: false,
|
||||
facts: facts,
|
||||
},
|
||||
];
|
||||
|
||||
if (enableTags && monitorJSON?.tags?.length > 0) {
|
||||
payloadBody.push({
|
||||
type: "Container",
|
||||
layouts: [
|
||||
{
|
||||
type: "Layout.Flow",
|
||||
columnSpacing: "Small",
|
||||
rowSpacing: "Small",
|
||||
horizontalItemsAlignment: "Left",
|
||||
},
|
||||
],
|
||||
items: monitorJSON.tags.map((tag) => {
|
||||
return {
|
||||
type: "Badge",
|
||||
text: this._tagDisplayText(tag),
|
||||
size: "Medium",
|
||||
style: "Accent",
|
||||
};
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
const payload = {
|
||||
type: "message",
|
||||
// message with status prefix as notification text
|
||||
@@ -103,59 +194,7 @@ class Teams extends NotificationProvider {
|
||||
contentUrl: "",
|
||||
content: {
|
||||
type: "AdaptiveCard",
|
||||
body: [
|
||||
{
|
||||
type: "Container",
|
||||
verticalContentAlignment: "Center",
|
||||
items: [
|
||||
{
|
||||
type: "ColumnSet",
|
||||
style: this._getStyle(status),
|
||||
columns: [
|
||||
{
|
||||
type: "Column",
|
||||
width: "auto",
|
||||
verticalContentAlignment: "Center",
|
||||
items: [
|
||||
{
|
||||
type: "Image",
|
||||
width: "32px",
|
||||
style: "Person",
|
||||
url: "https://raw.githubusercontent.com/louislam/uptime-kuma/master/public/icon.png",
|
||||
altText: "Uptime Kuma Logo",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "Column",
|
||||
width: "stretch",
|
||||
items: [
|
||||
{
|
||||
type: "TextBlock",
|
||||
size: "Medium",
|
||||
weight: "Bolder",
|
||||
text: `**${this._statusMessageFactory(status, monitorName, false)}**`,
|
||||
},
|
||||
{
|
||||
type: "TextBlock",
|
||||
size: "Small",
|
||||
weight: "Default",
|
||||
text: "Uptime Kuma Alert",
|
||||
isSubtle: true,
|
||||
spacing: "None",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
type: "FactSet",
|
||||
separator: false,
|
||||
facts: facts,
|
||||
},
|
||||
],
|
||||
body: payloadBody,
|
||||
$schema: "http://adaptivecards.io/schemas/adaptive-card.json",
|
||||
version: "1.5",
|
||||
},
|
||||
@@ -220,9 +259,9 @@ class Teams extends NotificationProvider {
|
||||
|
||||
const payload = this._notificationPayloadFactory({
|
||||
heartbeatJSON: heartbeatJSON,
|
||||
monitorName: monitorJSON.name,
|
||||
monitorUrl: this.extractAddress(monitorJSON),
|
||||
monitorJSON: monitorJSON,
|
||||
dashboardUrl: dashboardUrl,
|
||||
enableTags: notification.teamsEnableTags ?? false,
|
||||
});
|
||||
|
||||
await this._sendNotification(notification.webhookUrl, payload);
|
||||
|
||||
@@ -17,4 +17,15 @@
|
||||
</a>
|
||||
</i18n-t>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="form-check form-switch">
|
||||
<input v-model="$parent.notification.teamsEnableTags" class="form-check-input" type="checkbox" />
|
||||
<label class="form-check-label">{{ $t("teamsEnableTags") }}</label>
|
||||
</div>
|
||||
|
||||
<div class="form-text">
|
||||
{{ $t("teamsEnableTagsDescription") }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -640,6 +640,8 @@
|
||||
"whatHappensAtForumPost": "Create a new forum post. This does NOT post messages in existing post. To post in existing post use \"{option}\"",
|
||||
"wayToGetDiscordThreadId": "Getting a thread / forum post id is similar to getting a channel id. Read more about how to get ids {0}",
|
||||
"wayToGetTeamsURL": "You can learn how to create a webhook URL {0}.",
|
||||
"teamsEnableTags": "Include tags",
|
||||
"teamsEnableTagsDescription": "If enabled, the message will include the monitor tags.",
|
||||
"wayToGetZohoCliqURL": "You can learn how to create a webhook URL {0}.",
|
||||
"needSignalAPI": "You need to have a signal client with REST API.",
|
||||
"wayToCheckSignalURL": "You can check this URL to view how to set one up:",
|
||||
|
||||
Reference in New Issue
Block a user