Skip to content

Commit 85b55ab

Browse files
committed
Drop superfluous NotificationType mappings
1 parent 291f02b commit 85b55ab

File tree

3 files changed

+31
-97
lines changed

3 files changed

+31
-97
lines changed

cmd/icingadb-migrate/convert.go

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/icinga/icinga-go-library/database"
88
"github.com/icinga/icinga-go-library/types"
99
"github.com/icinga/icinga-go-library/utils"
10-
icingadbTypes "github.com/icinga/icingadb/pkg/icingadb/types"
1110
v1 "github.com/icinga/icingadb/pkg/icingadb/v1"
1211
"github.com/icinga/icingadb/pkg/icingadb/v1/history"
1312
"github.com/jmoiron/sqlx"
@@ -620,17 +619,15 @@ func convertNotificationRows(
620619
// migrated data itself via the history ID as object name, i.e. one "virtual object" per sent notification.
621620
name := strconv.FormatUint(row.NotificationId, 10)
622621

623-
nt := convertNotificationType(row.NotificationReason, row.State)
624-
625-
ntEnum, err := nt.Value()
622+
notificationType, err := convertNotificationType(row.NotificationReason, row.State)
626623
if err != nil {
627624
continue
628625
}
629626

630627
ts := convertTime(row.EndTime.Int64, row.EndTimeUsec)
631628
tsMilli := float64(ts.Time().UnixMilli())
632-
notificationHistoryId := hashAny([]interface{}{env, name, ntEnum, tsMilli})
633-
id := hashAny([]interface{}{env, "notification", name, ntEnum, tsMilli})
629+
notificationHistoryId := hashAny([]interface{}{env, name, notificationType, tsMilli})
630+
id := hashAny([]interface{}{env, "notification", name, notificationType, tsMilli})
634631
typ := objectTypes[row.ObjecttypeId]
635632
hostId := calcObjectId(env, row.Name1)
636633
serviceId := calcServiceId(env, row.Name1, row.Name2)
@@ -653,7 +650,7 @@ func convertNotificationRows(
653650
ServiceId: serviceId,
654651
},
655652
NotificationId: calcObjectId(env, name),
656-
Type: nt,
653+
Type: notificationType,
657654
SendTime: ts,
658655
State: row.State,
659656
PreviousHardState: previousHardState,
@@ -702,30 +699,30 @@ func convertNotificationRows(
702699
//
703700
// [1]: https://github.com/Icinga/icinga2/blob/32c7f7730db154ba0dff5856a8985d125791c/lib/db_ido/dbevents.cpp#L1507-L1524
704701
// [2]: https://github.com/Icinga/icingadb/blob/8f31ac143875498797725adb9bfacf3d4/pkg/types/notification_type.go#L53-L61
705-
func convertNotificationType(notificationReason, state uint8) icingadbTypes.NotificationType {
702+
func convertNotificationType(notificationReason, state uint8) (string, error) {
706703
switch notificationReason {
707704
case 0: // state
708705
if state == 0 {
709-
return 64 // recovery
706+
return "recovery", nil
710707
} else {
711-
return 32 // problem
708+
return "problem", nil
712709
}
713-
case 1: // acknowledgement
714-
return 16
715-
case 2: // flapping start
716-
return 128
717-
case 3: // flapping end
718-
return 256
719-
case 5: // downtime start
720-
return 1
721-
case 6: // downtime end
722-
return 2
723-
case 7: // downtime removed
724-
return 4
725-
case 8: // custom
726-
return 8
727-
default: // bad notification type
728-
return 0
710+
case 1:
711+
return "acknowledgement", nil
712+
case 2:
713+
return "flapping_start", nil
714+
case 3:
715+
return "flapping_end", nil
716+
case 5:
717+
return "downtime_start", nil
718+
case 6:
719+
return "downtime_end", nil
720+
case 7:
721+
return "downtime_removed", nil
722+
case 8:
723+
return "custom", nil
724+
default:
725+
return "", fmt.Errorf("bad notification type: %#v", notificationReason)
729726
}
730727
}
731728

pkg/icingadb/types/notification_type.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

pkg/icingadb/v1/history/notification.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,20 @@ package history
33
import (
44
"github.com/icinga/icinga-go-library/database"
55
"github.com/icinga/icinga-go-library/types"
6-
icingadbTypes "github.com/icinga/icingadb/pkg/icingadb/types"
76
v1 "github.com/icinga/icingadb/pkg/icingadb/v1"
87
)
98

109
type NotificationHistory struct {
1110
HistoryTableEntity `json:",inline"`
1211
HistoryTableMeta `json:",inline"`
13-
NotificationId types.Binary `json:"notification_id"`
14-
Type icingadbTypes.NotificationType `json:"type"`
15-
SendTime types.UnixMilli `json:"send_time"`
16-
State uint8 `json:"state"`
17-
PreviousHardState uint8 `json:"previous_hard_state"`
18-
Author string `json:"author"`
19-
Text types.String `json:"text"`
20-
UsersNotified uint16 `json:"users_notified"`
12+
NotificationId types.Binary `json:"notification_id"`
13+
Type string `json:"type"`
14+
SendTime types.UnixMilli `json:"send_time"`
15+
State uint8 `json:"state"`
16+
PreviousHardState uint8 `json:"previous_hard_state"`
17+
Author string `json:"author"`
18+
Text types.String `json:"text"`
19+
UsersNotified uint16 `json:"users_notified"`
2120
}
2221

2322
type UserNotificationHistory struct {

0 commit comments

Comments
 (0)