public void CloseIfStillOpen()
        {
            var config = GetPagerDutyConfig();
            var subject = "[IPHost] 'Parkmobile NL Web02 on web02-nl.parkmobile.com' - 'ok'";
            var api = new IntegrationApi(config);

            var incidents = api.GetOpenIncidents();

            var incident = incidents.FirstOrDefault(i => i.trigger_summary_data != null
                           && i.trigger_summary_data.IndexOf("IPHOST", StringComparison.OrdinalIgnoreCase) >= 0);

            if (incident != null)
            {
                var resolveEvent = new ResolveEvent(new IncidentEvent
                {
                    incident_key = incident.incident_key
                }, subject);

                var resResponse = api.Resolve(resolveEvent);

                Assert.IsTrue(resResponse.IsOk(), "Incident should be resolved");

            }
            else
            {
                //none open
            }
        }
 public PagerDutyHelper(PagerDutyConfig config)
 {
     _config = config;
     _apiClient = new IntegrationApi(config);
 }
 public void Init()
 {
     instance = new IntegrationApi();
 }
        public void CreateAcknowledgeResolve()
        {
            var config = GetPagerDutyConfig();

            /*var config = new PagerDutyConfig
                {
                    EventAuthToken = "YOUR_EVENT_API_KEY_HERE",
                    EventApiUrl = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
                };
            */

            var incident = new IncidentEvent
                {
                    client = "UnitTest",
                    description = "Event triggered by unittest",
                    incident_key = Guid.NewGuid().ToString(),
                    service_key = config.EventAuthToken,
                };

            var apiClient = new IntegrationApi(config);

            var response = apiClient.Trigger(incident);

            Assert.IsTrue(response.IsOk(), "Incident should be created");

            var acknowledge = new AcknowledgeEvent(incident, "Working on it!");

            var ackResponse = apiClient.Acknowledge(acknowledge);

            Assert.IsTrue(ackResponse.IsOk(), "Incident should be acknowledged");

            var resolveEvent = new ResolveEvent(incident, "Fixed!");

            var resResponse = apiClient.Resolve(resolveEvent);

            Assert.IsTrue(resResponse.IsOk(), "Incident should be resolved");
        }
        public void RaiseIfNotKnown()
        {
            var config = GetPagerDutyConfig();
            var subject = "[IPHost] 'Parkmobile NL Web02 on web02-nl.parkmobile.com' - 'down'";
            var api = new IntegrationApi(config);

            var incidents = api.GetOpenIncidents();

            var incident = incidents.FirstOrDefault(i => i.trigger_summary_data != null
                           && i.trigger_summary_data.IndexOf("IPHOST", StringComparison.OrdinalIgnoreCase) >= 0 );

            if (incident == null)
            {
                //raise new
                var newIncident = new IncidentEvent
                {
                    client = "IPHost",
                    description = subject,
                    incident_key = Guid.NewGuid().ToString(),
                    service_key = config.EventAuthToken,
                };

                var response = api.Trigger(newIncident);

                Assert.IsTrue(response.IsOk(), "Incident should be created");
            }
            else
            {
                //already known, keep on going
            }
        }
        public void GetOpenIndicidents()
        {
            var api = new IntegrationApi(GetPagerDutyConfig());

            var incidents = api.GetOpenIncidents();
            Assert.IsNotNull(incidents);
        }