diff --git a/App/FeatureSet/Notification/Templates/IncidentOwnerResourceCreated.hbs b/App/FeatureSet/Notification/Templates/IncidentOwnerResourceCreated.hbs index a38b62683a..1a7d9d6dd8 100644 --- a/App/FeatureSet/Notification/Templates/IncidentOwnerResourceCreated.hbs +++ b/App/FeatureSet/Notification/Templates/IncidentOwnerResourceCreated.hbs @@ -12,8 +12,8 @@ {{> DetailBoxField title="Incident Title:" text=incidentTitle }} {{> DetailBoxField title="Current State: " text=currentState }} {{> DetailBoxField title="Resources Affected: " text=resourcesAffected }} -{{> DetailBoxField title="Incident Created At: " text="" }} -{{> DetailBoxField title="" text=createdAt }} +{{> DetailBoxField title="Incident Declared At: " text="" }} +{{> DetailBoxField title="" text=declaredAt }} {{> DetailBoxField title="Severity: " text=incidentSeverity }} {{> DetailBoxField title="Root Cause: " text="" }} {{> DetailBoxField title="" text=rootCause }} diff --git a/App/FeatureSet/Notification/Templates/SubscriberAnnouncementCreated.hbs b/App/FeatureSet/Notification/Templates/SubscriberAnnouncementCreated.hbs index fd02f487c9..cd35ceec7e 100644 --- a/App/FeatureSet/Notification/Templates/SubscriberAnnouncementCreated.hbs +++ b/App/FeatureSet/Notification/Templates/SubscriberAnnouncementCreated.hbs @@ -8,8 +8,6 @@ {{> DetailBoxStart this }} {{> DetailBoxField title=announcementTitle text="" }} {{> DetailBoxField title="" text=announcementDescription }} -{{> DetailBoxField title="Posted At: " text="" }} -{{> DetailBoxField title="" text=showAnnouncementAt }} {{> DetailBoxEnd this }} {{> InfoBlock info=(concat "This is an automated email sent to you because you are subscribed to " statusPageName) }} diff --git a/App/FeatureSet/Notification/Templates/SubscriberIncidentCreated.hbs b/App/FeatureSet/Notification/Templates/SubscriberIncidentCreated.hbs index 19f77dd445..bb88c703c6 100644 --- a/App/FeatureSet/Notification/Templates/SubscriberIncidentCreated.hbs +++ b/App/FeatureSet/Notification/Templates/SubscriberIncidentCreated.hbs @@ -12,8 +12,6 @@ {{> DetailBoxField title=incidentTitle text="" }} {{> DetailBoxField title="Resources Affected: " text=resourcesAffected }} {{> DetailBoxField title="Severity: " text=incidentSeverity }} -{{> DetailBoxField title="Created At: " text="" }} -{{> DetailBoxField title="" text=createdAt }} {{> DetailBoxField title="Description: " text="" }} {{> DetailBoxField title="" text=incidentDescription }} {{> DetailBoxEnd this }} diff --git a/App/FeatureSet/Workers/Jobs/Announcement/SendNotificationToSubscribers.ts b/App/FeatureSet/Workers/Jobs/Announcement/SendNotificationToSubscribers.ts index f9c51fb902..8840048cc1 100644 --- a/App/FeatureSet/Workers/Jobs/Announcement/SendNotificationToSubscribers.ts +++ b/App/FeatureSet/Workers/Jobs/Announcement/SendNotificationToSubscribers.ts @@ -63,9 +63,12 @@ RunCron( continue; } - const statusPages: Array = await StatusPageSubscriberService.getStatusPagesToSendNotification(announcement.statusPages.map((sp: StatusPage) => { - return sp.id!; - })); + const statusPages: Array = + await StatusPageSubscriberService.getStatusPagesToSendNotification( + announcement.statusPages.map((sp: StatusPage) => { + return sp.id!; + }), + ); await StatusPageAnnouncementService.updateOneById({ id: announcement.id!, @@ -79,9 +82,7 @@ RunCron( }); for (const statuspage of statusPages) { - try { - if (!statuspage.id) { continue; } @@ -95,18 +96,15 @@ RunCron( }, ); - const statusPageURL: string = await StatusPageService.getStatusPageURL( - statuspage.id, - ); + const statusPageURL: string = + await StatusPageService.getStatusPageURL(statuspage.id); const statusPageName: string = statuspage.pageTitle || statuspage.name || "Status Page"; // Send email to Email subscribers. for (const subscriber of subscribers) { - try { - if (!subscriber._id) { continue; } @@ -134,9 +132,10 @@ RunCron( // send sms here. SmsService.sendSms(sms, { projectId: statuspage.projectId, - customTwilioConfig: ProjectCallSMSConfigService.toTwilioConfig( - statuspage.callSmsConfig, - ), + customTwilioConfig: + ProjectCallSMSConfigService.toTwilioConfig( + statuspage.callSmsConfig, + ), }).catch((err: Error) => { logger.error(err); }); @@ -148,21 +147,16 @@ RunCron( MailService.sendMail( { toEmail: subscriber.subscriberEmail, - templateType: EmailTemplateType.SubscriberAnnouncementCreated, + templateType: + EmailTemplateType.SubscriberAnnouncementCreated, vars: { statusPageName: statusPageName, statusPageUrl: statusPageURL, - showAnnouncementAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones( - { - date: announcement.showAnnouncementAt!, - timezones: statuspage.subscriberTimezones || [], - }, - ), logoUrl: statuspage.logoFileId ? new URL(httpProtocol, host) - .addRoute(FileRoute) - .addRoute("/image/" + statuspage.logoFileId) - .toString() + .addRoute(FileRoute) + .addRoute("/image/" + statuspage.logoFileId) + .toString() : "", isPublicStatusPage: statuspage.isPublicStatusPage ? "true" diff --git a/App/FeatureSet/Workers/Jobs/Incident/SendNotificationToSubscribers.ts b/App/FeatureSet/Workers/Jobs/Incident/SendNotificationToSubscribers.ts index ac553e4c06..41cbf1f271 100644 --- a/App/FeatureSet/Workers/Jobs/Incident/SendNotificationToSubscribers.ts +++ b/App/FeatureSet/Workers/Jobs/Incident/SendNotificationToSubscribers.ts @@ -78,9 +78,6 @@ RunCron( // get status page resources from monitors. - - const incidentIdentifiedDate: Date = await IncidentService.getIncidentIdentifiedDate(incident.id!); - const statusPageResources: Array = await StatusPageResourceService.findBy({ query: { @@ -131,7 +128,6 @@ RunCron( ); for (const statuspage of statusPages) { - try { if (!statuspage.id) { continue; @@ -146,9 +142,8 @@ RunCron( }, ); - const statusPageURL: string = await StatusPageService.getStatusPageURL( - statuspage.id, - ); + const statusPageURL: string = + await StatusPageService.getStatusPageURL(statuspage.id); const statusPageName: string = statuspage.pageTitle || statuspage.name || "Status Page"; @@ -162,9 +157,7 @@ RunCron( .join(", ") || "None"; for (const subscriber of subscribers) { - try { - if (!subscriber._id) { continue; } @@ -172,7 +165,8 @@ RunCron( const shouldNotifySubscriber: boolean = StatusPageSubscriberService.shouldSendNotification({ subscriber: subscriber, - statusPageResources: statusPageToResources[statuspage._id!] || [], + statusPageResources: + statusPageToResources[statuspage._id!] || [], statusPage: statuspage, }); @@ -187,11 +181,8 @@ RunCron( ).toString(); if (subscriber.subscriberEmail) { - // send email here. - - MailService.sendMail( { toEmail: subscriber.subscriberEmail, @@ -201,21 +192,16 @@ RunCron( statusPageUrl: statusPageURL, logoUrl: statuspage.logoFileId ? new URL(httpProtocol, host) - .addRoute(FileRoute) - .addRoute("/image/" + statuspage.logoFileId) - .toString() + .addRoute(FileRoute) + .addRoute("/image/" + statuspage.logoFileId) + .toString() : "", isPublicStatusPage: statuspage.isPublicStatusPage ? "true" : "false", resourcesAffected: resourcesAffectedString, - createdAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones( - { - date: incidentIdentifiedDate, - timezones: statuspage.subscriberTimezones || [], - }, - ), - incidentSeverity: incident.incidentSeverity?.name || " - ", + incidentSeverity: + incident.incidentSeverity?.name || " - ", incidentTitle: incident.title || "", incidentDescription: await Markdown.convertToHTML( incident.description || "", @@ -243,8 +229,9 @@ RunCron( Title: ${incident.title || ""} - Severity: ${incident.incidentSeverity?.name || " - " - } + Severity: ${ + incident.incidentSeverity?.name || " - " + } Resources Affected: ${resourcesAffectedString} @@ -258,9 +245,10 @@ RunCron( // send sms here. SmsService.sendSms(sms, { projectId: statuspage.projectId, - customTwilioConfig: ProjectCallSMSConfigService.toTwilioConfig( - statuspage.callSmsConfig, - ), + customTwilioConfig: + ProjectCallSMSConfigService.toTwilioConfig( + statuspage.callSmsConfig, + ), }).catch((err: Error) => { logger.error(err); }); diff --git a/App/FeatureSet/Workers/Jobs/IncidentOwners/SendCreatedResourceNotification.ts b/App/FeatureSet/Workers/Jobs/IncidentOwners/SendCreatedResourceNotification.ts index c110c26f73..90b0355e1b 100644 --- a/App/FeatureSet/Workers/Jobs/IncidentOwners/SendCreatedResourceNotification.ts +++ b/App/FeatureSet/Workers/Jobs/IncidentOwners/SendCreatedResourceNotification.ts @@ -52,6 +52,9 @@ RunCron( }); for (const incident of incidents) { + const incidentIdentifiedDate: Date = + await IncidentService.getIncidentIdentifiedDate(incident.id!); + await IncidentService.updateOneById({ id: incident.id!, data: { @@ -79,9 +82,7 @@ RunCron( continue; } - for (const user of owners) { - const vars: Dictionary = { incidentTitle: incident.title!, projectName: incident.project!.name!, @@ -97,8 +98,8 @@ RunCron( }) .join(", ") || "None", incidentSeverity: incident.incidentSeverity!.name!, - createdAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones({ - date: incident.createdAt!, + declaredAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones({ + date: incidentIdentifiedDate, timezones: user.timezone ? [user.timezone] : [], }), rootCause: @@ -110,10 +111,10 @@ RunCron( ) ).toString(), }; - + if (doesResourceHasOwners === true) { vars["isOwner"] = "true"; - } + } const emailMessage: EmailEnvelope = { templateType: EmailTemplateType.IncidentOwnerResourceCreated, diff --git a/App/FeatureSet/Workers/Jobs/ScheduledMaintenanceOwners/SendStateChangeNotification.ts b/App/FeatureSet/Workers/Jobs/ScheduledMaintenanceOwners/SendStateChangeNotification.ts index da5702c772..74def03ae8 100644 --- a/App/FeatureSet/Workers/Jobs/ScheduledMaintenanceOwners/SendStateChangeNotification.ts +++ b/App/FeatureSet/Workers/Jobs/ScheduledMaintenanceOwners/SendStateChangeNotification.ts @@ -38,6 +38,7 @@ RunCron( select: { _id: true, createdAt: true, + startsAt: true, projectId: true, project: { name: true, @@ -101,7 +102,7 @@ RunCron( ), stateChangedAt: OneUptimeDate.getDateAsFormattedHTMLInMultipleTimezones({ - date: scheduledMaintenanceStateTimeline.createdAt!, + date: scheduledMaintenanceStateTimeline.startsAt!, timezones: user.timezone ? [user.timezone] : [], }), scheduledMaintenanceViewLink: ( diff --git a/Common/Types/Date.ts b/Common/Types/Date.ts index bfae9114a2..44fa6d8691 100644 --- a/Common/Types/Date.ts +++ b/Common/Types/Date.ts @@ -1012,10 +1012,10 @@ export default class OneUptimeDate { } public static getZoneAbbrByTimezone(timezone: Timezone): string { - let zoneAbbr = moment.tz(timezone).zoneAbbr(); + let zoneAbbr: string = moment.tz(timezone).zoneAbbr(); - if(zoneAbbr.startsWith('+') || zoneAbbr.startsWith('-')) { - zoneAbbr = 'GMT' + zoneAbbr; + if (zoneAbbr.startsWith("+") || zoneAbbr.startsWith("-")) { + zoneAbbr = "GMT" + zoneAbbr; } return zoneAbbr; @@ -1059,7 +1059,7 @@ export default class OneUptimeDate { return moment(date["value"]).toDate(); } - throw new BadDataException("Invalid date: "+date.toString()); + throw new BadDataException("Invalid date: " + date.toString()); } public static asDateForDatabaseQuery(date: string | Date): string { diff --git a/CommonServer/Services/IncidentService.ts b/CommonServer/Services/IncidentService.ts index aef1abb16c..3351777771 100644 --- a/CommonServer/Services/IncidentService.ts +++ b/CommonServer/Services/IncidentService.ts @@ -269,22 +269,22 @@ export class Service extends DatabaseService { return createdItem; } - public async getIncidentIdentifiedDate(incidentId: ObjectID): Promise { - const timeline: IncidentStateTimeline | null = await IncidentStateTimelineService.findOneBy({ - query: { - incidentId: incidentId, - }, - select: { - startsAt: true, - }, - sort: { - startsAt: SortOrder.Ascending, - }, - props: { - isRoot: true, - }, - }); + const timeline: IncidentStateTimeline | null = + await IncidentStateTimelineService.findOneBy({ + query: { + incidentId: incidentId, + }, + select: { + startsAt: true, + }, + sort: { + startsAt: SortOrder.Ascending, + }, + props: { + isRoot: true, + }, + }); if (!timeline || !timeline.startsAt) { throw new BadDataException("Incident identified date not found."); diff --git a/Ingestor/API/Monitor.ts b/Ingestor/API/Monitor.ts index abe1aec917..b67c64feb1 100644 --- a/Ingestor/API/Monitor.ts +++ b/Ingestor/API/Monitor.ts @@ -177,10 +177,9 @@ router.get( count: monitorProbesCount.toNumber(), nextPingAt: firstMonitorToBeFetched?.nextPingAt, friendlyNextPingAt: firstMonitorToBeFetched?.nextPingAt - ? OneUptimeDate.getDateAsFormattedStringInMultipleTimezones( - {date: firstMonitorToBeFetched?.nextPingAt - }, - ) + ? OneUptimeDate.getDateAsFormattedStringInMultipleTimezones({ + date: firstMonitorToBeFetched?.nextPingAt, + }) : "", }); } catch (err) {