mirror of
https://github.com/nezhahq/nezha.git
synced 2025-02-08 12:38:13 -05:00
前端更新: 支持报警规则绑定触发任务
This commit is contained in:
parent
13d1be59b6
commit
93e1d58bcb
@ -33,6 +33,7 @@ func (ma *memberAPI) serve() {
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
mr.GET("/search-server", ma.searchServer)
|
mr.GET("/search-server", ma.searchServer)
|
||||||
|
mr.GET("/search-tasks", ma.searchTask)
|
||||||
mr.POST("/server", ma.addOrEditServer)
|
mr.POST("/server", ma.addOrEditServer)
|
||||||
mr.POST("/monitor", ma.addOrEditMonitor)
|
mr.POST("/monitor", ma.addOrEditMonitor)
|
||||||
mr.POST("/cron", ma.addOrEditCron)
|
mr.POST("/cron", ma.addOrEditCron)
|
||||||
@ -275,6 +276,27 @@ func (ma *memberAPI) searchServer(c *gin.Context) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ma *memberAPI) searchTask(c *gin.Context) {
|
||||||
|
var tasks []model.Cron
|
||||||
|
likeWord := "%" + c.Query("word") + "%"
|
||||||
|
singleton.DB.Select("id,name").Where("id = ? OR name LIKE ?",
|
||||||
|
c.Query("word"), likeWord).Find(&tasks)
|
||||||
|
|
||||||
|
var resp []searchResult
|
||||||
|
for i := 0; i < len(tasks); i++ {
|
||||||
|
resp = append(resp, searchResult{
|
||||||
|
Value: tasks[i].ID,
|
||||||
|
Name: tasks[i].Name,
|
||||||
|
Text: tasks[i].Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
c.JSON(http.StatusOK, map[string]interface{}{
|
||||||
|
"success": true,
|
||||||
|
"results": resp,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
type serverForm struct {
|
type serverForm struct {
|
||||||
ID uint64
|
ID uint64
|
||||||
Name string `binding:"required"`
|
Name string `binding:"required"`
|
||||||
|
21
resource/l10n/zh-CN.toml
vendored
21
resource/l10n/zh-CN.toml
vendored
@ -70,6 +70,9 @@ other = "忽略所有,仅通过特定服务器执行"
|
|||||||
[AllIncludedOnlySpecificServersAreNotExecuted]
|
[AllIncludedOnlySpecificServersAreNotExecuted]
|
||||||
other = "覆盖所有,仅特定服务器不执行"
|
other = "覆盖所有,仅特定服务器不执行"
|
||||||
|
|
||||||
|
[ExecuteByTriggerServer]
|
||||||
|
other = "由触发的服务器执行"
|
||||||
|
|
||||||
[SpecificServers]
|
[SpecificServers]
|
||||||
other = "特定服务器"
|
other = "特定服务器"
|
||||||
|
|
||||||
@ -82,6 +85,15 @@ other = "通知方式组"
|
|||||||
[PushSuccessMessages]
|
[PushSuccessMessages]
|
||||||
other = "推送成功的消息"
|
other = "推送成功的消息"
|
||||||
|
|
||||||
|
[TaskType]
|
||||||
|
other = "任务类型"
|
||||||
|
|
||||||
|
[CronTask]
|
||||||
|
other = "计划任务"
|
||||||
|
|
||||||
|
[TriggerTask]
|
||||||
|
other = "触发任务"
|
||||||
|
|
||||||
[TheFormaOfTheScheduleIs]
|
[TheFormaOfTheScheduleIs]
|
||||||
other = "计划的格式为:"
|
other = "计划的格式为:"
|
||||||
|
|
||||||
@ -157,6 +169,12 @@ other = "始终触发"
|
|||||||
[ModeOnetimeTrigger]
|
[ModeOnetimeTrigger]
|
||||||
other = "单次触发"
|
other = "单次触发"
|
||||||
|
|
||||||
|
[FailTriggerTasks]
|
||||||
|
other = "故障时触发任务"
|
||||||
|
|
||||||
|
[RecoverTriggerTasks]
|
||||||
|
other = "恢复时触发任务"
|
||||||
|
|
||||||
[Enable]
|
[Enable]
|
||||||
other = "启用"
|
other = "启用"
|
||||||
|
|
||||||
@ -205,6 +223,9 @@ other = "覆盖所有"
|
|||||||
[IgnoreAll]
|
[IgnoreAll]
|
||||||
other = "忽略所有"
|
other = "忽略所有"
|
||||||
|
|
||||||
|
[ByTrigger]
|
||||||
|
other = "触发执行"
|
||||||
|
|
||||||
[DeleteScheduledTask]
|
[DeleteScheduledTask]
|
||||||
other = "删除计划任务"
|
other = "删除计划任务"
|
||||||
|
|
||||||
|
@ -70,6 +70,7 @@ function showFormModal(modelSelector, formID, URL, getData) {
|
|||||||
item.name === "RequestType" ||
|
item.name === "RequestType" ||
|
||||||
item.name === "RequestMethod" ||
|
item.name === "RequestMethod" ||
|
||||||
item.name === "TriggerMode" ||
|
item.name === "TriggerMode" ||
|
||||||
|
item.name === "TaskType" ||
|
||||||
item.name === "DisplayIndex" ||
|
item.name === "DisplayIndex" ||
|
||||||
item.name === "Type" ||
|
item.name === "Type" ||
|
||||||
item.name === "Cover" ||
|
item.name === "Cover" ||
|
||||||
@ -90,6 +91,16 @@ function showFormModal(modelSelector, formID, URL, getData) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (item.name.endsWith("TasksRaw")) {
|
||||||
|
if (item.value.length > 2) {
|
||||||
|
obj[item.name] = JSON.stringify(
|
||||||
|
[...item.value.matchAll(/\d+/gm)].map((k) =>
|
||||||
|
parseInt(k[0])
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return obj;
|
return obj;
|
||||||
}, {});
|
}, {});
|
||||||
$.post(URL, JSON.stringify(data))
|
$.post(URL, JSON.stringify(data))
|
||||||
@ -138,6 +149,44 @@ function addOrEditAlertRule(rule) {
|
|||||||
} else {
|
} else {
|
||||||
modal.find(".ui.rule-enable.checkbox").checkbox("set unchecked");
|
modal.find(".ui.rule-enable.checkbox").checkbox("set unchecked");
|
||||||
}
|
}
|
||||||
|
modal.find("a.ui.label.visible").each((i, el) => {
|
||||||
|
el.remove();
|
||||||
|
});
|
||||||
|
var failTriggerTasks;
|
||||||
|
var recoverTriggerTasks;
|
||||||
|
if (rule) {
|
||||||
|
failTriggerTasks = rule.FailTriggerTasksRaw;
|
||||||
|
recoverTriggerTasks = rule.RecoverTriggerTasksRaw;
|
||||||
|
const failTriggerTasksList = JSON.parse(failTriggerTasks || "[]");
|
||||||
|
const recoverTriggerTasksList = JSON.parse(recoverTriggerTasks || "[]");
|
||||||
|
const node1 = modal.find("i.dropdown.icon.1");
|
||||||
|
const node2 = modal.find("i.dropdown.icon.2");
|
||||||
|
for (let i = 0; i < failTriggerTasksList.length; i++) {
|
||||||
|
node1.after(
|
||||||
|
'<a class="ui label transition visible" data-value="' +
|
||||||
|
failTriggerTasksList[i] +
|
||||||
|
'" style="display: inline-block !important;">ID:' +
|
||||||
|
failTriggerTasksList[i] +
|
||||||
|
'<i class="delete icon"></i></a>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
for (let i = 0; i < recoverTriggerTasksList.length; i++) {
|
||||||
|
node2.after(
|
||||||
|
'<a class="ui label transition visible" data-value="' +
|
||||||
|
recoverTriggerTasksList[i] +
|
||||||
|
'" style="display: inline-block !important;">ID:' +
|
||||||
|
recoverTriggerTasksList[i] +
|
||||||
|
'<i class="delete icon"></i></a>'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
modal
|
||||||
|
.find("input[name=FailTriggerTasksRaw]")
|
||||||
|
.val(rule ? "[]," + failTriggerTasks.substr(1, failTriggerTasks.length - 2) : "[]");
|
||||||
|
modal
|
||||||
|
.find("input[name=RecoverTriggerTasksRaw]")
|
||||||
|
.val(rule ? "[]," + recoverTriggerTasks.substr(1, recoverTriggerTasks.length - 2) : "[]");
|
||||||
|
|
||||||
showFormModal(".rule.modal", "#ruleForm", "/api/alert-rule");
|
showFormModal(".rule.modal", "#ruleForm", "/api/alert-rule");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -298,6 +347,8 @@ function addOrEditCron(cron) {
|
|||||||
);
|
);
|
||||||
modal.find("input[name=ID]").val(cron ? cron.ID : null);
|
modal.find("input[name=ID]").val(cron ? cron.ID : null);
|
||||||
modal.find("input[name=Name]").val(cron ? cron.Name : null);
|
modal.find("input[name=Name]").val(cron ? cron.Name : null);
|
||||||
|
modal.find("select[name=TaskType]").val(cron ? cron.TaskType : 0);
|
||||||
|
modal.find("select[name=Cover]").val(cron ? cron.Cover : 0);
|
||||||
modal.find("input[name=NotificationTag]").val(cron ? cron.NotificationTag : null);
|
modal.find("input[name=NotificationTag]").val(cron ? cron.NotificationTag : null);
|
||||||
modal.find("input[name=Scheduler]").val(cron ? cron.Scheduler : null);
|
modal.find("input[name=Scheduler]").val(cron ? cron.Scheduler : null);
|
||||||
modal.find("a.ui.label.visible").each((i, el) => {
|
modal.find("a.ui.label.visible").each((i, el) => {
|
||||||
@ -435,3 +486,15 @@ $(document).ready(() => {
|
|||||||
});
|
});
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document).ready(() => {
|
||||||
|
try {
|
||||||
|
$(".ui.tasks.search.dropdown").dropdown({
|
||||||
|
clearable: true,
|
||||||
|
apiSettings: {
|
||||||
|
url: "/api/search-tasks?word={query}",
|
||||||
|
cache: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) { }
|
||||||
|
});
|
||||||
|
8
resource/template/component/cron.html
vendored
8
resource/template/component/cron.html
vendored
@ -8,6 +8,13 @@
|
|||||||
<label>{{tr "Name"}}</label>
|
<label>{{tr "Name"}}</label>
|
||||||
<input type="text" name="Name" placeholder="{{tr "BackUp"}}">
|
<input type="text" name="Name" placeholder="{{tr "BackUp"}}">
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>{{tr "TaskType"}}</label>
|
||||||
|
<select name="TaskType" class="ui fluid dropdown">
|
||||||
|
<option value="0">{{tr "CronTask"}}</option>
|
||||||
|
<option value="1">{{tr "TriggerTask"}}</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>{{tr "Scheduler"}}</label>
|
<label>{{tr "Scheduler"}}</label>
|
||||||
<input type="text" name="Scheduler" placeholder="0 0 3 * * *{{tr "3amDaily"}}">
|
<input type="text" name="Scheduler" placeholder="0 0 3 * * *{{tr "3amDaily"}}">
|
||||||
@ -21,6 +28,7 @@
|
|||||||
<select name="Cover" class="ui fluid dropdown">
|
<select name="Cover" class="ui fluid dropdown">
|
||||||
<option value="0">{{tr "IgnoreAllAndExecuteOnlyThroughSpecificServers"}}</option>
|
<option value="0">{{tr "IgnoreAllAndExecuteOnlyThroughSpecificServers"}}</option>
|
||||||
<option value="1">{{tr "AllIncludedOnlySpecificServersAreNotExecuted"}}</option>
|
<option value="1">{{tr "AllIncludedOnlySpecificServersAreNotExecuted"}}</option>
|
||||||
|
<option value="2">{{tr "ExecuteByTriggerServer"}}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
19
resource/template/component/rule.html
vendored
19
resource/template/component/rule.html
vendored
@ -23,6 +23,25 @@
|
|||||||
<option value="1">{{tr "ModeOnetimeTrigger"}}</option>
|
<option value="1">{{tr "ModeOnetimeTrigger"}}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>{{tr "FailTriggerTasks"}}</label>
|
||||||
|
<div class="ui fluid multiple tasks search selection dropdown">
|
||||||
|
<input type="hidden" name="FailTriggerTasksRaw">
|
||||||
|
<i class="dropdown icon 1"></i>
|
||||||
|
<div class="default text">{{tr "EnterIdAndNameToSearch"}}</div>
|
||||||
|
<div class="menu"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label>{{tr "RecoverTriggerTasks"}}</label>
|
||||||
|
<div class="ui fluid multiple tasks search selection dropdown">
|
||||||
|
<input type="hidden" name="RecoverTriggerTasksRaw">
|
||||||
|
<i class="dropdown icon 2"></i>
|
||||||
|
<div class="default text">{{tr "EnterIdAndNameToSearch"}}</div>
|
||||||
|
<div class="menu"></div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<div class="ui rule-enable checkbox">
|
<div class="ui rule-enable checkbox">
|
||||||
<input name="Enable" type="checkbox" tabindex="0" class="hidden">
|
<input name="Enable" type="checkbox" tabindex="0" class="hidden">
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>ID</th>
|
<th>ID</th>
|
||||||
<th>{{tr "Name"}}</th>
|
<th>{{tr "Name"}}</th>
|
||||||
|
<th>{{tr "TaskType"}}</th>
|
||||||
<th>{{tr "Scheduler"}}</th>
|
<th>{{tr "Scheduler"}}</th>
|
||||||
<th>{{tr "Command"}}</th>
|
<th>{{tr "Command"}}</th>
|
||||||
<th>{{tr "NotificationMethodGroup"}}</th>
|
<th>{{tr "NotificationMethodGroup"}}</th>
|
||||||
@ -31,11 +32,12 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{$cron.ID}}</td>
|
<td>{{$cron.ID}}</td>
|
||||||
<td>{{$cron.Name}}</td>
|
<td>{{$cron.Name}}</td>
|
||||||
|
<td>{{if eq $cron.TaskType 0}}{{tr "CronTask"}}{{else}}{{tr "TriggerTask"}}{{end}}</td>
|
||||||
<td>{{$cron.Scheduler}}</td>
|
<td>{{$cron.Scheduler}}</td>
|
||||||
<td>{{$cron.Command}}</td>
|
<td>{{$cron.Command}}</td>
|
||||||
<td>{{$cron.NotificationTag}}</td>
|
<td>{{$cron.NotificationTag}}</td>
|
||||||
<td>{{$cron.PushSuccessful}}</td>
|
<td>{{$cron.PushSuccessful}}</td>
|
||||||
<td>{{if eq $cron.Cover 0}}{{tr "IgnoreAll"}}{{else}}{{tr "CoverAll"}}{{end}}</td>
|
<td>{{if eq $cron.Cover 0}}{{tr "IgnoreAll"}}{{else if eq $cron.Cover 1}}{{tr "CoverAll"}}{{else}}{{tr "ByTrigger"}}{{end}}</td>
|
||||||
<td>{{$cron.ServersRaw}}</td>
|
<td>{{$cron.ServersRaw}}</td>
|
||||||
<td>{{$cron.LastExecutedAt|tf}}</td>
|
<td>{{$cron.LastExecutedAt|tf}}</td>
|
||||||
<td>{{$cron.LastResult}}</td>
|
<td>{{$cron.LastResult}}</td>
|
||||||
|
@ -60,6 +60,8 @@
|
|||||||
<th>{{tr "NotificationMethodGroup"}}</th>
|
<th>{{tr "NotificationMethodGroup"}}</th>
|
||||||
<th>{{tr "NotificationTriggerMode"}}</th>
|
<th>{{tr "NotificationTriggerMode"}}</th>
|
||||||
<th>{{tr "Rules"}}</th>
|
<th>{{tr "Rules"}}</th>
|
||||||
|
<th>{{tr "FailTriggerTasks"}}</th>
|
||||||
|
<th>{{tr "RecoverTriggerTasks"}}</th>
|
||||||
<th>{{tr "Enable"}}</th>
|
<th>{{tr "Enable"}}</th>
|
||||||
<th>{{tr "Administration"}}</th>
|
<th>{{tr "Administration"}}</th>
|
||||||
</tr>
|
</tr>
|
||||||
@ -72,6 +74,8 @@
|
|||||||
<td>{{$rule.NotificationTag}}</td>
|
<td>{{$rule.NotificationTag}}</td>
|
||||||
<td>{{if eq $rule.TriggerMode 0}}{{tr "ModeAlwaysTrigger"}}{{else}}{{tr "ModeOnetimeTrigger"}}{{end}}
|
<td>{{if eq $rule.TriggerMode 0}}{{tr "ModeAlwaysTrigger"}}{{else}}{{tr "ModeOnetimeTrigger"}}{{end}}
|
||||||
<td>{{$rule.RulesRaw}}</td>
|
<td>{{$rule.RulesRaw}}</td>
|
||||||
|
<td>{{$rule.FailTriggerTasksRaw}}</td>
|
||||||
|
<td>{{$rule.RecoverTriggerTasksRaw}}</td>
|
||||||
<td>{{$rule.Enable}}</td>
|
<td>{{$rule.Enable}}</td>
|
||||||
<td>
|
<td>
|
||||||
<div class="ui mini icon buttons">
|
<div class="ui mini icon buttons">
|
||||||
|
Loading…
Reference in New Issue
Block a user