-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feature) add script for generating alert
- Loading branch information
1 parent
2a69c52
commit 48af715
Showing
3 changed files
with
41 additions
and
2 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
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,37 @@ | ||
import yargs from "yargs" | ||
import { AlertType } from "@common/enums" | ||
import { ALERT_TYPE_TO_RISK_SCORE } from "@common/maps" | ||
import { AppDataSource } from "data-source" | ||
import { Alert } from "models" | ||
import { DatabaseService } from "services/database" | ||
|
||
const generateAlert = async (alertType: string, apiEndpointUuid: string, description: string, context: any) => { | ||
try{ | ||
const newAlert = new Alert() | ||
newAlert.apiEndpointUuid = apiEndpointUuid | ||
newAlert.type = AlertType[alertType] | ||
newAlert.description = description | ||
newAlert.riskScore = ALERT_TYPE_TO_RISK_SCORE[AlertType[alertType]] | ||
newAlert.context = JSON.parse(context || "{}") | ||
await DatabaseService.executeTransactions([[newAlert]], [], false) | ||
} catch (err) { | ||
console.error(`Error generating new alert from script: ${err}`) | ||
} | ||
} | ||
|
||
const main = async () => { | ||
const datasource = await AppDataSource.initialize() | ||
if (!datasource.isInitialized) { | ||
console.error("Couldn't initialize datasource...") | ||
return | ||
} | ||
console.log("AppDataSource Initialized...") | ||
const args = yargs.argv | ||
const alertType = args["alertType"] | ||
const apiEndpointUuid = args["endpointUuid"] | ||
const description = args["description"] | ||
const context = args["context"] | ||
await generateAlert(alertType, apiEndpointUuid, description, context) | ||
} | ||
|
||
main() |
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