Exemplo n.º 1
0
        private bool CheckAuthority(string level)
        {
            var authority = AkkaHelper.ReadConfigurationFromHoconFile(Assembly.GetExecutingAssembly(), "conf")
                            .WithFallback(ConfigurationFactory
                                          .FromResource <ConsumerSettings <object, object> >("Akka.Streams.Kafka.reference.conf"))
                            .GetInt("ui.notification.authority-level");

            if (authority < Int32.Parse(level))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public ParserActor(IActorRef notificationActor)
        {
            Receive <ConsumeResult <Null, string> >(msg =>
            {
                var msgLength = AkkaHelper.ReadConfigurationFromHoconFile(Assembly.GetExecutingAssembly(), "conf")
                                .WithFallback(ConfigurationFactory
                                              .FromResource <ConsumerSettings <object, object> >("Akka.Streams.Kafka.reference.conf"))
                                .GetInt("ui.notification.message-length");

                dynamic json = JsonConvert.DeserializeObject(msg.Value, new JsonSerializerSettings()
                {
                    DateTimeZoneHandling = DateTimeZoneHandling.Local,
                });

                var level = json.jsonMessage["severity"].ToString();
                if (!CheckAuthority(level))
                {
                    return;
                }

                string localtime = json["@timestamp"].ToString("yyyy-MM-dd HH:mm:ss.ff") + "(" + json["@timestamp"].ToString("ddd") + ")";
                string alertInfo = System.Environment.NewLine + json.jsonMessage["monitor_name"] + " : " + json.jsonMessage["trigger_name"];
                string hosts     = GetHosts(json.jsonMessage["host_name"].Value);

                var title   = string.Format($"[{level}] {localtime}");
                var message = new StringBuilder().AppendLine(alertInfo).AppendLine(hosts).ToString();

                if (message.Length > msgLength)
                {
                    message = string.Concat(message.ToString().Remove(msgLength), "...");
                }

                var content = new NotificationMessage()
                {
                    Title = title, Message = message
                };
                notificationActor.Tell(
                    ((NotificationLevel)Enum.Parse(typeof(NotificationLevel), GetSeverity(level), true), content)
                    );
            });
        }