fix(notify): add server_panic topic (#15826)

This commit is contained in:
gouqi11
2023-01-18 23:34:18 +08:00
committed by GitHub
parent 02b2f780ec
commit 3db8a61d16
10 changed files with 28 additions and 9 deletions
@@ -0,0 +1,2 @@
{{- $d := .resource_details -}}
您在{{ $d.project }}项目的虚拟机{{ $d.name }}崩溃了
@@ -0,0 +1,2 @@
{{- $d := .resource_details -}}
The server {{ $d.name }} in project {{ $d.project }} panicked.
@@ -0,0 +1,2 @@
{{- $d := .resource_details -}}
您在{{ $d.project }}项目的虚拟机{{ $d.name }}崩溃了
@@ -0,0 +1,2 @@
{{- $d := .resource_details -}}
The server {{ $d.name }} in project {{ $d.project }}panicked.
+1
View File
@@ -59,6 +59,7 @@ var (
ActionNetOutOfSync SAction = "net_out_of_sync"
ActionMysqlOutOfSync SAction = "mysql_out_of_sync"
ActionServiceAbnormal SAction = "service_abnormal"
ActionServerPanicked SAction = "server_panicked"
ResultFailed SResult = "failed"
ResultSucceed SResult = "succeed"
+1
View File
@@ -59,6 +59,7 @@ var (
ActionNetOutOfSync = api.ActionNetOutOfSync
ActionMysqlOutOfSync = api.ActionMysqlOutOfSync
ActionServiceAbnormal = api.ActionServiceAbnormal
ActionServerPanicked = api.ActionServerPanicked
ActionPendingDelete = api.ActionPendingDelete
+5 -7
View File
@@ -140,13 +140,11 @@ func (self *SGuest) PerformEvent(ctx context.Context, userCred mcclient.TokenCre
db.OpsLog.LogEvent(self, db.ACT_GUEST_PANICKED, data.String(), userCred)
logclient.AddSimpleActionLog(self, logclient.ACT_GUEST_PANICKED, data.String(), userCred, true)
self.NotifyServerEvent(
ctx,
userCred,
notifyclient.SERVER_PANICKED,
notify.NotifyPriorityNormal,
false, kwargs, true,
)
notifyclient.EventNotify(ctx, userCred, notifyclient.SEventNotifyParam{
Obj: self,
Action: notifyclient.ActionServerPanicked,
IsFail: true,
})
}
return nil, nil
}
+1 -1
View File
@@ -650,7 +650,7 @@ func dataCleaning(tableName string) error {
now := time.Now()
monthsDaysAgo := now.AddDate(0, -1, 0).Format("2006-01-02 15:04:05")
sqlStr := fmt.Sprintf(
"update %s set deleted = 1 where deleted = 0 and created_at < '%s'",
"delete from %s where created_at < '%s'",
tableName,
monthsDaysAgo,
)
-1
View File
@@ -85,7 +85,6 @@ func (rm *SRobotManager) InitializeData() error {
}
rq := RobotManager.Query()
rq = rq.Filter(sqlchemy.OR(sqlchemy.IsEmpty(rq.Field("tenant_id")), sqlchemy.Equals(rq.Field("tenant_id"), "system")))
rq.DebugQuery()
npRobots := make([]SRobot, 0)
err = db.FetchModelObjects(RobotManager, rq, &npRobots)
if err != nil {
+12
View File
@@ -101,6 +101,7 @@ const (
DefaultNetOutOfSync = "net out of sync"
DefaultMysqlOutOfSync = "mysql out of sync"
DefaultServiceAbnormal = "service abnormal"
DefaultServerPanicked = "server panicked"
)
func (sm *STopicManager) InitializeData() error {
@@ -126,6 +127,7 @@ func (sm *STopicManager) InitializeData() error {
DefaultNetOutOfSync,
DefaultMysqlOutOfSync,
DefaultServiceAbnormal,
DefaultServerPanicked,
)
q := sm.Query()
topics := make([]STopic, 0, initSNames.Len())
@@ -411,6 +413,15 @@ func (sm *STopicManager) InitializeData() error {
)
t.Results = tristate.True
t.Type = notify.TOPIC_TYPE_AUTOMATED_PROCESS
case DefaultServerPanicked:
t.addResources(
notify.TOPIC_RESOURCE_SERVER,
)
t.addAction(
notify.ActionServerPanicked,
)
t.Results = tristate.False
t.Type = notify.TOPIC_TYPE_RESOURCE
}
if topic == nil {
err := sm.TableSpec().Insert(ctx, t)
@@ -676,6 +687,7 @@ func init() {
notify.ActionNetOutOfSync: 26,
notify.ActionMysqlOutOfSync: 27,
notify.ActionServiceAbnormal: 28,
notify.ActionServerPanicked: 29,
},
)
}