-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: instastatus integration (#971)
* feat: instastatus integration * fix: delete pageID in instatus * fix: create api pageID and components * fixed error input incidents in instatus * fix: eslint * fix: get page id from Monika configuration * update clean eslint * feat: change incident status type * feat: instastatus integration * fix: delete pageID in instatus * fix: create api pageID and components * fixed error input incidents in instatus * fix: eslint * fix: get page id from Monika configuration * create readme notification instatus * clean eslint * fix readme notification * fix: conflict validate * change description instatus in monika-config-schema --------- Co-authored-by: Hari Cahya Nugraha <[email protected]> Co-authored-by: Nico Prananta <[email protected]>
- Loading branch information
1 parent
089325d
commit c2c12d1
Showing
12 changed files
with
417 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,15 @@ | ||
-- instatus_page_incidents definition | ||
|
||
-- Drop Table | ||
DROP TABLE IF EXISTS instatus_page_incidents; | ||
-- Create Table | ||
CREATE TABLE instatus_page_incidents ( | ||
id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, | ||
status TEXT NOT NULL, | ||
url TEXT NOT NULL, | ||
probe_id INTEGER NOT NULL, | ||
incident_id TEXT NOT NULL, | ||
created_at INTEGER NOT NULL, | ||
updated_at INTEGER NOT NULL); | ||
|
||
CREATE INDEX instatus_page_incidents_incident_id_IDX ON instatus_page_incidents (incident_id); |
This file contains 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 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 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 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 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 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 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 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 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 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,62 @@ | ||
import { db } from '../../../components/logger/history' | ||
|
||
type Incident = { | ||
id: string | ||
status: string | ||
url: string | ||
probeID: string | ||
incidentID: string | ||
} | ||
type InsertIncident = Omit<Incident, 'id'> | ||
type UpdateIncident = Pick<Incident, 'incidentID' | 'status'> | ||
type FindIncident = Pick<Incident, 'probeID' | 'status' | 'url'> | ||
|
||
type FindIncidentResponse = { | ||
// eslint-disable-next-line camelcase | ||
incident_id: string | ||
} | ||
|
||
export async function insertIncident({ | ||
status, | ||
url, | ||
probeID, | ||
incidentID, | ||
}: InsertIncident): Promise<void> { | ||
const dateNow = Math.round(Date.now() / 1000) | ||
const sqlStatement = `INSERT INTO instatus_page_incidents ( | ||
status, | ||
url, | ||
probe_id, | ||
incident_id, | ||
created_at, | ||
updated_at | ||
) VALUES (?, ?, ?, ?, ?, ?);` | ||
const sqlParams = [status, url, probeID, incidentID, dateNow, dateNow] | ||
|
||
await db.run(sqlStatement, sqlParams) | ||
} | ||
|
||
export async function updateIncident({ | ||
incidentID, | ||
status, | ||
}: UpdateIncident): Promise<void> { | ||
const dateNow = Math.round(Date.now() / 1000) | ||
const sqlStatement = `UPDATE instatus_page_incidents SET status = ?, updated_at = ? | ||
WHERE incident_id = ?` | ||
const sqlParams = [status, dateNow, incidentID] | ||
|
||
await db.run(sqlStatement, sqlParams) | ||
} | ||
|
||
export async function findIncident({ | ||
probeID, | ||
status, | ||
url, | ||
}: FindIncident): Promise<FindIncidentResponse | undefined> { | ||
const sqlStatement = `SELECT incident_id FROM instatus_page_incidents | ||
WHERE status = ? AND url = ? AND probe_id = ?` | ||
const sqlParams = [status, url, probeID] | ||
const incident = await db.get<FindIncidentResponse>(sqlStatement, sqlParams) | ||
|
||
return incident | ||
} |
Oops, something went wrong.