8
8
"github.com/icinga/icinga-go-library/types"
9
9
"github.com/icinga/icinga-go-library/utils"
10
10
"github.com/icinga/icingadb/pkg/common"
11
- icingadbTypes "github.com/icinga/icingadb/pkg/icingadb/types"
12
11
v1 "github.com/icinga/icingadb/pkg/icingadb/v1"
13
12
"github.com/icinga/icingadb/pkg/icingadb/v1/history"
14
13
"github.com/jmoiron/sqlx"
@@ -621,17 +620,16 @@ func convertNotificationRows(
621
620
// migrated data itself via the history ID as object name, i.e. one "virtual object" per sent notification.
622
621
name := strconv .FormatUint (row .NotificationId , 10 )
623
622
624
- nt := convertNotificationType (row .NotificationReason , row .State )
625
-
626
- ntEnum , err := nt .Value ()
623
+ notificationType , err := convertNotificationType (row .NotificationReason , row .State )
627
624
if err != nil {
625
+ log .With ("notification_reason" , row .NotificationReason , "state" , row .State ).Errorf ("%+v" , err )
628
626
continue
629
627
}
630
628
631
629
ts := convertTime (row .EndTime .Int64 , row .EndTimeUsec )
632
630
tsMilli := float64 (ts .Time ().UnixMilli ())
633
- notificationHistoryId := hashAny ([]interface {}{env , name , ntEnum , tsMilli })
634
- id := hashAny ([]interface {}{env , "notification" , name , ntEnum , tsMilli })
631
+ notificationHistoryId := hashAny ([]interface {}{env , name , notificationType , tsMilli })
632
+ id := hashAny ([]interface {}{env , "notification" , name , notificationType , tsMilli })
635
633
typ := objectTypes [row .ObjecttypeId ]
636
634
hostId := calcObjectId (env , row .Name1 )
637
635
serviceId := calcServiceId (env , row .Name1 , row .Name2 )
@@ -654,7 +652,7 @@ func convertNotificationRows(
654
652
ServiceId : serviceId ,
655
653
},
656
654
NotificationId : calcObjectId (env , name ),
657
- Type : nt ,
655
+ Type : history . NotificationType ( notificationType ) ,
658
656
SendTime : ts ,
659
657
State : row .State ,
660
658
PreviousHardState : previousHardState ,
@@ -699,34 +697,34 @@ func convertNotificationRows(
699
697
return
700
698
}
701
699
702
- // convertNotificationType maps IDO values[ 1] to Icinga DB ones[ 2].
700
+ // convertNotificationType maps IDO values [^ 1] to their Icinga DB counterparts [^ 2].
703
701
//
704
- // [1]: https://github.com/Icinga/icinga2/blob/32c7f7730db154ba0dff5856a8985d125791c/lib/db_ido/dbevents.cpp#L1507-L1524
705
- // [2]: https://github.com/Icinga/icingadb /blob/8f31ac143875498797725adb9bfacf3d4/pkg/types/notification_type.go#L53-L61
706
- func convertNotificationType (notificationReason , state uint8 ) icingadbTypes. NotificationType {
702
+ // [^ 1]: https://github.com/Icinga/icinga2/blob/32c7f7730db154ba0dff5856a8985d125791c/lib/db_ido/dbevents.cpp#L1507-L1524
703
+ // [^ 2]: https://github.com/Icinga/icinga2 /blob/32c7f7730db154ba0dff5856a8985d125791c73e/lib/icingadb/icingadb-utility.cpp#L157-L176
704
+ func convertNotificationType (notificationReason , state uint8 ) ( string , error ) {
707
705
switch notificationReason {
708
706
case 0 : // state
709
707
if state == 0 {
710
- return 64 // recovery
708
+ return " recovery" , nil
711
709
} else {
712
- return 32 // problem
710
+ return " problem" , nil
713
711
}
714
- case 1 : // acknowledgement
715
- return 16
716
- case 2 : // flapping start
717
- return 128
718
- case 3 : // flapping end
719
- return 256
720
- case 5 : // downtime start
721
- return 1
722
- case 6 : // downtime end
723
- return 2
724
- case 7 : // downtime removed
725
- return 4
726
- case 8 : // custom
727
- return 8
728
- default : // bad notification type
729
- return 0
712
+ case 1 :
713
+ return "acknowledgement" , nil
714
+ case 2 :
715
+ return "flapping_start" , nil
716
+ case 3 :
717
+ return "flapping_end" , nil
718
+ case 5 :
719
+ return "downtime_start" , nil
720
+ case 6 :
721
+ return "downtime_end" , nil
722
+ case 7 :
723
+ return "downtime_removed" , nil
724
+ case 8 :
725
+ return "custom" , nil
726
+ default :
727
+ return "" , fmt . Errorf ( "bad notification type: %d" , notificationReason )
730
728
}
731
729
}
732
730
0 commit comments