Example #1
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement alertNode = document.CreateElement("idmef:Heartbeat", "http://iana.org/idmef");

            alertNode.SetAttribute("messageId", messageId);

            alertNode.AppendChild(analyzer.ToXml(document));
            alertNode.AppendChild(createTime.ToXml(document));
            if (heartbeatInterval != null)
            {
                XmlElement subNode     = document.CreateElement("idmef:HeartbeatInterval", "http://iana.org/idmef");
                XmlNode    subNodeText = document.CreateNode(XmlNodeType.Text, "idmef", "HeartbeatInterval", "http://iana.org/idmef");

                subNodeText.Value = heartbeatInterval.ToString();

                subNode.AppendChild(subNodeText);
                alertNode.AppendChild(subNode);
            }
            if (analyzerTime != null)
            {
                alertNode.AppendChild(analyzerTime.ToXml(document));
            }
            if (additionalData != null)
            {
                foreach (var ad in additionalData)
                {
                    if (ad != null)
                    {
                        alertNode.AppendChild(ad.ToXml(document));
                    }
                }
            }

            return(alertNode);
        }
Example #2
0
        public XmlElement ToXml(XmlDocument document)
        {
            XmlElement alertNode = document.CreateElement("idmef:Alert", "http://iana.org/idmef");

            alertNode.SetAttribute("messageId", messageId);

            alertNode.AppendChild(analyzer.ToXml(document));
            alertNode.AppendChild(createTime.ToXml(document));
            alertNode.AppendChild(classification.ToXml(document));
            if (detectTime != null)
            {
                alertNode.AppendChild(detectTime.ToXml(document));
            }
            if (analyzerTime != null)
            {
                alertNode.AppendChild(analyzerTime.ToXml(document));
            }
            if (source != null)
            {
                foreach (var src in source)
                {
                    if (src != null)
                    {
                        alertNode.AppendChild(src.ToXml(document));
                    }
                }
            }
            if (target != null)
            {
                foreach (var tgt in target)
                {
                    if (tgt != null)
                    {
                        alertNode.AppendChild(tgt.ToXml(document));
                    }
                }
            }
            if (assessment != null)
            {
                alertNode.AppendChild(assessment.ToXml(document));
            }

            int subs = 0;

            if (toolAlert != null)
            {
                subs++;
                alertNode.AppendChild(toolAlert.ToXml(document));
            }
            if (overflowAlert != null)
            {
                subs++;
                alertNode.AppendChild(overflowAlert.ToXml(document));
            }
            if (correlationAlert != null)
            {
                subs++;
                alertNode.AppendChild(correlationAlert.ToXml(document));
            }
            if (subs > 1)
            {
                throw new InvalidOperationException("Only one subclass of Alert can be attached.");
            }

            if (additionalData != null)
            {
                foreach (var ad in additionalData)
                {
                    if (ad != null)
                    {
                        alertNode.AppendChild(ad.ToXml(document));
                    }
                }
            }

            return(alertNode);
        }