feat: 计划任务失败告警支持全类型告警 (#6749)

This commit is contained in:
2024-10-17 15:27:31 +08:00 committed by GitHub
parent b99061777a
commit 227cc57426
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 41 additions and 48 deletions

View File

@ -25,8 +25,6 @@ import (
"github.com/pkg/errors"
)
var alertTypes = map[string]bool{"app": true, "website": true, "database": true, "directory": true, "log": true, "snapshot": true}
func (u *CronjobService) HandleJob(cronjob *model.Cronjob) {
var (
message []byte
@ -398,17 +396,15 @@ func hasBackup(cronjobType string) bool {
}
func handleCronJobAlert(cronjob *model.Cronjob) {
if alertTypes[cronjob.Type] {
pushAlert := dto.PushAlert{
TaskName: cronjob.Name,
AlertType: cronjob.Type,
EntryID: cronjob.ID,
Param: cronjob.Type,
}
err := xpack.PushAlert(pushAlert)
if err != nil {
global.LOG.Errorf("cronjob alert push failed, err: %v", err)
return
}
pushAlert := dto.PushAlert{
TaskName: cronjob.Name,
AlertType: cronjob.Type,
EntryID: cronjob.ID,
Param: cronjob.Type,
}
err := xpack.PushAlert(pushAlert)
if err != nil {
global.LOG.Errorf("cronjob alert push failed, err: %v", err)
return
}
}

View File

@ -1133,7 +1133,7 @@ const message = {
clamLog: 'Scan Logs',
freshClam: 'Update Virus Definitions',
freshClamLog: 'Update Virus Definitions Logs',
alertHelper: 'Professional version supports SMS alert',
alertHelper: 'Professional version supports scheduled scan and SMS alert',
alertTitle: 'Virus scanning {0} task failed alert',
},
},

View File

@ -1070,7 +1070,7 @@ const message = {
clamLog: '掃描日誌',
freshClam: '病毒庫刷新配置',
freshClamLog: '病毒庫刷新日誌',
alertHelper: '專業版支持短信告警功能',
alertHelper: '專業版支持定時掃描和短信告警功能',
alertTitle: '病毒掃描{0}任務失敗告警',
},
},
@ -2292,7 +2292,7 @@ const message = {
isAlert: '是否告警',
alertCount: '告警次數',
clamHelper: '掃描到感染檔案時觸發簡訊告警',
cronJobHelper: '定時執行計畫任務失敗時觸發簡訊告警',
cronJobHelper: '定時任務執行失敗時觸發簡訊告警',
licenseHelper: '專業版支持簡訊告警功能',
alertCountHelper: '每日最大告警次數',
},

View File

@ -1072,7 +1072,7 @@ const message = {
clamLog: '扫描日志',
freshClam: '病毒库刷新配置',
freshClamLog: '病毒库刷新日志',
alertHelper: '专业版支持短信告警功能',
alertHelper: '专业版支持定时扫描和短信告警功能',
alertTitle: '病毒扫描 {0} 任务失败告警',
},
},
@ -2295,7 +2295,7 @@ const message = {
isAlert: '是否告警',
alertCount: '告警次数',
clamHelper: '扫描到感染文件时触发短信告警',
cronJobHelper: '定时执行计划任务失败时触发短信告警',
cronJobHelper: '定时任务执行失败时触发短信告警',
licenseHelper: '专业版支持短信告警功能',
alertCountHelper: '每日最大告警次数',
},

View File

@ -320,23 +320,7 @@
</el-form-item>
</div>
<el-form-item :label="$t('cronjob.retainCopies')" prop="retainCopies">
<el-input-number
style="width: 200px"
:min="1"
step-strictly
:step="1"
v-model.number="dialogData.rowData!.retainCopies"
></el-input-number>
<span v-if="isBackup()" class="input-help">{{ $t('cronjob.retainCopiesHelper1') }}</span>
<span v-else class="input-help">{{ $t('cronjob.retainCopiesHelper') }}</span>
</el-form-item>
<el-form-item v-if="dialogData.rowData!.type === 'curl'" :label="$t('cronjob.url')" prop="url">
<el-input clearable v-model.trim="dialogData.rowData!.url" />
</el-form-item>
<el-form-item prop="hasAlert" v-if="alertTypes.includes(dialogData.rowData!.type)">
<el-form-item prop="hasAlert">
<el-checkbox v-model="dialogData.rowData!.hasAlert" :label="$t('alert.isAlert')" />
<span class="input-help">{{ $t('alert.cronJobHelper') }}</span>
</el-form-item>
@ -361,6 +345,22 @@
</el-button>
</el-form-item>
<el-form-item :label="$t('cronjob.retainCopies')" prop="retainCopies">
<el-input-number
style="width: 200px"
:min="1"
step-strictly
:step="1"
v-model.number="dialogData.rowData!.retainCopies"
></el-input-number>
<span v-if="isBackup()" class="input-help">{{ $t('cronjob.retainCopiesHelper1') }}</span>
<span v-else class="input-help">{{ $t('cronjob.retainCopiesHelper') }}</span>
</el-form-item>
<el-form-item v-if="dialogData.rowData!.type === 'curl'" :label="$t('cronjob.url')" prop="url">
<el-input clearable v-model.trim="dialogData.rowData!.url" />
</el-form-item>
<el-form-item
v-if="hasExclusionRules()"
:label="$t('cronjob.exclusionRules')"
@ -429,7 +429,6 @@ const dialogData = ref<DialogProps>({
const globalStore = GlobalStore();
const licenseRef = ref();
const { isProductPro } = storeToRefs(globalStore);
const alertTypes = ['app', 'website', 'database', 'directory', 'log', 'snapshot'];
const acceptParams = (params: DialogProps): void => {
dialogData.value = params;
@ -805,17 +804,15 @@ const onSubmit = async (formEl: FormInstance | undefined) => {
if (dialogData.value?.rowData?.exclusionRules) {
dialogData.value.rowData.exclusionRules = dialogData.value.rowData.exclusionRules.replaceAll('\n', ',');
}
if (alertTypes.includes(dialogData.value.rowData.type)) {
dialogData.value.rowData.alertCount =
dialogData.value.rowData!.hasAlert && isProductPro.value ? dialogData.value.rowData.alertCount : 0;
dialogData.value.rowData.alertTitle =
dialogData.value.rowData!.hasAlert && isProductPro.value
? i18n.global.t('cronjob.alertTitle', [
i18n.global.t('cronjob.' + dialogData.value.rowData.type),
dialogData.value.rowData.name,
])
: '';
}
dialogData.value.rowData.alertCount =
dialogData.value.rowData!.hasAlert && isProductPro.value ? dialogData.value.rowData.alertCount : 0;
dialogData.value.rowData.alertTitle =
dialogData.value.rowData!.hasAlert && isProductPro.value
? i18n.global.t('cronjob.alertTitle', [
i18n.global.t('cronjob.' + dialogData.value.rowData.type),
dialogData.value.rowData.name,
])
: '';
if (!dialogData.value.rowData) return;
if (dialogData.value.title === 'create') {
await addCronjob(dialogData.value.rowData);