Пример #1
0
        public void Flow(DockerEvent dockerEvent)
        {
            string containerId   = dockerEvent.Actor?.ID?.Substring(0, 8);
            string containerName = dockerEvent.Actor?.Attributes?.Name;

            string msg = $"Container *{dockerEvent.Action}* : {containerId} ({containerName})";

            System.Console.WriteLine(msg);
        }
Пример #2
0
        public SlackNotification Parse(DockerEvent dockerEvent)
        {
            string containerId = dockerEvent.Actor?.ID?.Substring(0, 8);
            string containerName = dockerEvent.Actor?.Attributes?.Name;

            string fallbackMsg = $"Container *{dockerEvent.Action}* : {containerId} ({containerName})";

            string color = dockerEvent.Action == "start" ? "good" : "danger";

            List<SlackAttachmentField> attachmentFields = new List<SlackAttachmentField>
            {
                new SlackAttachmentField
                {
                    Title = "Action",
                    Value = dockerEvent.Action,
                    Short = true
                },
                new SlackAttachmentField
                {
                    Title = "ID",
                    Value = containerId,
                    Short = true
                },
                new SlackAttachmentField
                {
                    Title = "Name",
                    Value = containerName,
                    Short = true
                },
                new SlackAttachmentField
                {
                    Title = "Image",
                    Value = dockerEvent.Actor?.Attributes?.Image,
                    Short = true
                }
            };

            List<SlackAttachment> attachments = new List<SlackAttachment>
            {
                new SlackAttachment
                {
                    Fallback = fallbackMsg,
                    Color = color,
                    Fields = attachmentFields,
                    MarkdownIn = new [] { "fallback", "text", "pretext", "fields" }
                }
            };

            SlackNotification notification = new SlackNotification
            {
                Text = fallbackMsg,
                Attachments = attachments
            };

            return notification;
        }
Пример #3
0
        /// <summary>
        ///		Create a new <see cref="DockerEventParser"/> actor.
        /// </summary>
        /// <param name="correlationId">
        ///		The message correlation Id that will be sent with the stream data.
        /// </param>
        /// <param name="owner">
        ///		The actor that owns the <see cref="DockerEventParser"/> actor (this actor will receive the stream data).
        /// </param>
        /// <param name="stream">
        ///		The <see cref="Stream"/> to read from.
        /// </param>
        /// <param name="bufferSize">
        ///		The buffer size to use when reading from the stream.
        /// </param>
        public DockerEventParser(string correlationId, IActorRef owner, Stream stream, int bufferSize)
        {
            if (String.IsNullOrWhiteSpace(correlationId))
            {
                throw new ArgumentException($"Argument cannot be null, empty, or entirely composed of whitespace: {nameof(correlationId)}.", nameof(correlationId));
            }

            if (owner == null)
            {
                throw new ArgumentNullException(nameof(owner));
            }

            if (stream == null)
            {
                throw new ArgumentNullException(nameof(stream));
            }

            _owner            = owner;
            _streamLinesProps = StreamLines.Create(correlationId, Self, stream, Encoding.ASCII, bufferSize);

            Receive <StreamLines.StreamLine>(streamLine =>
            {
                var parsedEvent = DockerEvent.FromJson(streamLine.Line, correlationId);

                _owner.Tell(parsedEvent);
            });
            Receive <ReadStream.StreamError>(error =>
            {
                _owner.Tell(error);
            });
            Receive <Terminated>(terminated =>
            {
                if (terminated.ActorRef.Equals(_owner))
                {
                    Log.Debug("Owner '{0}' terminated.", _owner);

                    Context.Stop(Self);
                }
                else if (terminated.ActorRef.Equals(_streamLines))
                {
                    Log.Debug("Streamer '{0}' terminated.", _streamLines);

                    Context.Stop(Self);
                }
                else
                {
                    Unhandled(terminated);
                }
            });
        }
Пример #4
0
        public void Flow(DockerEvent dockerEvent)
        {
            if (dockerEvent.Type != "container")
            {
                return;
            }

            if (!new List <string> {
                "start", "stop"
            }.Contains(dockerEvent.Action))
            {
                return;
            }

            var notification = _options.DockerEventParser.Parse(dockerEvent);

            postNotification(notification).Wait();
        }