-
-
Notifications
You must be signed in to change notification settings - Fork 360
Add UptimeRobot incident reporting integration #5282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
inodb
wants to merge
1
commit into
cBioPortal:master
Choose a base branch
from
inodb:add-uptime-robot
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import { IUserMessage } from 'shared/components/userMessager/UserMessage'; | ||
|
|
||
| /** | ||
| * Interface for status page integrations. | ||
| * Each status provider (UptimeRobot, StatusPage.io, etc.) implements this interface | ||
| * to provide status messages that will be displayed as banners. | ||
| */ | ||
| export interface IStatusProvider { | ||
| /** | ||
| * Fetches active status messages from the provider. | ||
| * @returns Promise resolving to an array of user messages | ||
| */ | ||
| fetchMessages(): Promise<IUserMessage[]>; | ||
| } |
65 changes: 65 additions & 0 deletions
65
src/shared/lib/statusProviders/UptimeRobotStatusProvider.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import * as React from 'react'; | ||
| import { IStatusProvider } from './IStatusProvider'; | ||
| import { IUserMessage } from 'shared/components/userMessager/UserMessage'; | ||
| import { | ||
| fetchUptimeRobotEvents, | ||
| getActiveEvents, | ||
| getEventSeverityColor, | ||
| UptimeRobotEvent, | ||
| } from './uptimeRobot'; | ||
|
|
||
| /** | ||
| * Status provider for UptimeRobot integration. | ||
| * Fetches events from UptimeRobot status page and converts them to banner messages. | ||
| */ | ||
| export class UptimeRobotStatusProvider implements IStatusProvider { | ||
| async fetchMessages(): Promise<IUserMessage[]> { | ||
| try { | ||
| const eventFeed = await fetchUptimeRobotEvents(); | ||
| if (!eventFeed || !eventFeed.results) { | ||
| return []; | ||
| } | ||
|
|
||
| const activeEvents = getActiveEvents(eventFeed.results); | ||
| const statusPageUrl = eventFeed.statusPageUrl; | ||
|
|
||
| return activeEvents.map((event: UptimeRobotEvent) => { | ||
| const endTime = event.endDateGMT | ||
| ? new Date(event.endDateGMT).getTime() | ||
| : Date.now() + 24 * 60 * 60 * 1000; // Default to 24 hours from now | ||
|
|
||
| return { | ||
| id: `uptime-robot-${event.id}`, | ||
| dateEnd: endTime, | ||
| content: ( | ||
| <div> | ||
| <strong>{event.title}</strong> | ||
| {event.description && ( | ||
| <> | ||
| {': '} | ||
| {event.description} | ||
| </> | ||
| )} | ||
| {statusPageUrl && ( | ||
| <> | ||
| {' '} | ||
| <a | ||
| href={statusPageUrl} | ||
| target="_blank" | ||
| rel="noopener noreferrer" | ||
| > | ||
| View status page | ||
| </a> | ||
| </> | ||
| )} | ||
| </div> | ||
| ), | ||
| backgroundColor: getEventSeverityColor(event.icon), | ||
| }; | ||
| }); | ||
| } catch (error) { | ||
| console.error('Error fetching UptimeRobot messages:', error); | ||
| return []; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import { IStatusProvider } from './IStatusProvider'; | ||
| import { UptimeRobotStatusProvider } from './UptimeRobotStatusProvider'; | ||
|
|
||
| /** | ||
| * Registry of all status page providers. | ||
| * Add new status providers here to enable them. | ||
| * | ||
| * Example: To add StatusPage.io integration: | ||
| * 1. Create StatusPageIoProvider.ts that implements IStatusProvider | ||
| * 2. Import it: import { StatusPageIoProvider } from './StatusPageIoProvider'; | ||
| * 3. Add to array: new StatusPageIoProvider(), | ||
| */ | ||
| export const STATUS_PROVIDERS: IStatusProvider[] = [ | ||
| new UptimeRobotStatusProvider(), | ||
| // Add additional status providers here | ||
| ]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import { getServerConfig } from 'config/config'; | ||
|
|
||
| export interface UptimeRobotEvent { | ||
| type: 'announcement' | 'update'; | ||
| eventType: string; | ||
| id: number; | ||
| title: string; | ||
| content: string; | ||
| description: string; | ||
| date: string; | ||
| time: string; | ||
| timeGMT: string; | ||
| endDate?: string; | ||
| endDateGMT?: string; | ||
| timestamp: number; | ||
| status: number; // 1 = resolved, 2 = active/ongoing | ||
| icon: string; | ||
| } | ||
|
|
||
| export interface UptimeRobotEventFeedResponse { | ||
| status: boolean; | ||
| results: UptimeRobotEvent[]; | ||
| meta: { | ||
| count: number; | ||
| date_range: { | ||
| from: string; | ||
| to: string; | ||
| }; | ||
| }; | ||
| statusPageUrl?: string; // Added to track the status page URL | ||
| } | ||
|
|
||
| /** | ||
| * Fetches the event feed from UptimeRobot status page | ||
| * @returns Promise resolving to the event feed response | ||
| */ | ||
| export async function fetchUptimeRobotEvents(): Promise<UptimeRobotEventFeedResponse | null> { | ||
| const config = getServerConfig(); | ||
|
|
||
| // Check if UptimeRobot is configured (both URL and API key required) | ||
| if (!config.uptime_robot_status_page_url || !config.uptime_robot_api_key) { | ||
| return null; | ||
| } | ||
|
|
||
| try { | ||
| const url = `${config.uptime_robot_status_page_url}/api/getEventFeed/${config.uptime_robot_api_key}`; | ||
| const response = await fetch(url); | ||
inodb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!response.ok) { | ||
| console.error( | ||
| 'Failed to fetch UptimeRobot events:', | ||
| response.statusText | ||
| ); | ||
| return null; | ||
| } | ||
|
|
||
| const data: UptimeRobotEventFeedResponse = await response.json(); | ||
| // Add the status page URL to the response so we can link to it | ||
| data.statusPageUrl = config.uptime_robot_status_page_url; | ||
| return data; | ||
| } catch (error) { | ||
| console.error('Error fetching UptimeRobot events:', error); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Filters events to return only active/ongoing events | ||
| * @param events Array of UptimeRobot events | ||
| * @returns Array of active events | ||
| */ | ||
| export function getActiveEvents( | ||
| events: UptimeRobotEvent[] | ||
| ): UptimeRobotEvent[] { | ||
| const now = Date.now(); | ||
|
|
||
| return events.filter(event => { | ||
| // Status 2 indicates active/ongoing event | ||
| const isActive = event.status === 2; | ||
|
|
||
| // Check if event is still within its time window | ||
| const startTime = event.timestamp * 1000; // Convert to milliseconds | ||
| const hasStarted = startTime <= now; | ||
|
|
||
| // If there's an end date, check if it hasn't passed yet | ||
| let notEnded = true; | ||
| if (event.endDateGMT) { | ||
| const endTime = new Date(event.endDateGMT).getTime(); | ||
| notEnded = endTime > now; | ||
| } | ||
|
|
||
| return isActive && hasStarted && notEnded; | ||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * Converts UptimeRobot event severity icon to appropriate CSS class/color | ||
| * @param icon The icon name from UptimeRobot | ||
| * @returns CSS color for the banner | ||
| */ | ||
| export function getEventSeverityColor(icon: string): string { | ||
| switch (icon) { | ||
| case 'alert-triangle': | ||
| case 'alert-octagon': | ||
| return '#d9534f'; // Red/danger | ||
| case 'alert-circle': | ||
| return '#f0ad4e'; // Orange/warning | ||
| case 'info': | ||
| return '#5bc0de'; // Blue/info | ||
| case 'check-circle': | ||
| return '#5cb85c'; // Green/success | ||
| default: | ||
| return '#f0ad4e'; // Default to warning | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.