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

pull/6757/head
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" "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) { func (u *CronjobService) HandleJob(cronjob *model.Cronjob) {
var ( var (
message []byte message []byte
@ -398,17 +396,15 @@ func hasBackup(cronjobType string) bool {
} }
func handleCronJobAlert(cronjob *model.Cronjob) { func handleCronJobAlert(cronjob *model.Cronjob) {
if alertTypes[cronjob.Type] { pushAlert := dto.PushAlert{
pushAlert := dto.PushAlert{ TaskName: cronjob.Name,
TaskName: cronjob.Name, AlertType: cronjob.Type,
AlertType: cronjob.Type, EntryID: cronjob.ID,
EntryID: cronjob.ID, Param: cronjob.Type,
Param: cronjob.Type, }
} err := xpack.PushAlert(pushAlert)
err := xpack.PushAlert(pushAlert) if err != nil {
if err != nil { global.LOG.Errorf("cronjob alert push failed, err: %v", err)
global.LOG.Errorf("cronjob alert push failed, err: %v", err) return
return
}
} }
} }

View File

@ -1133,7 +1133,7 @@ const message = {
clamLog: 'Scan Logs', clamLog: 'Scan Logs',
freshClam: 'Update Virus Definitions', freshClam: 'Update Virus Definitions',
freshClamLog: 'Update Virus Definitions Logs', 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', alertTitle: 'Virus scanning {0} task failed alert',
}, },
}, },

View File

@ -1070,7 +1070,7 @@ const message = {
clamLog: '', clamLog: '',
freshClam: '', freshClam: '',
freshClamLog: '', freshClamLog: '',
alertHelper: '', alertHelper: '',
alertTitle: '{0}', alertTitle: '{0}',
}, },
}, },
@ -2292,7 +2292,7 @@ const message = {
isAlert: '', isAlert: '',
alertCount: '', alertCount: '',
clamHelper: '', clamHelper: '',
cronJobHelper: '', cronJobHelper: '',
licenseHelper: '', licenseHelper: '',
alertCountHelper: '', alertCountHelper: '',
}, },

View File

@ -1072,7 +1072,7 @@ const message = {
clamLog: '', clamLog: '',
freshClam: '', freshClam: '',
freshClamLog: '', freshClamLog: '',
alertHelper: '', alertHelper: '',
alertTitle: ' {0} ', alertTitle: ' {0} ',
}, },
}, },
@ -2295,7 +2295,7 @@ const message = {
isAlert: '', isAlert: '',
alertCount: '', alertCount: '',
clamHelper: '', clamHelper: '',
cronJobHelper: '', cronJobHelper: '',
licenseHelper: '', licenseHelper: '',
alertCountHelper: '', alertCountHelper: '',
}, },

View File

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