-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
31 additions
and
14 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 |
---|---|---|
|
@@ -47,7 +47,6 @@ router.post("/", (req: Request, res: Response) => { | |
|
||
|
||
|
||
const UPTIME_CHECK_INTERVAL = process.env.UPTIME_CHECK_INTERVAL || 60000; // Default: 1 minute | ||
|
||
|
||
const EMAIL_USERNAME = process.env.EMAIL_USERNAME; | ||
|
@@ -72,31 +71,41 @@ const transporter = nodemailer.createTransport({ | |
|
||
const EMAIL_LIST = ["[email protected]"]; | ||
|
||
var email_sent = false | ||
|
||
export async function checkUptime() { | ||
|
||
const subject = "API DOWN"; | ||
|
||
const mailOptions = { | ||
from: EMAIL_USERNAME, // Replace with your Gmail email | ||
to: EMAIL_LIST.join(", "), | ||
subject, | ||
text: subject, | ||
}; | ||
|
||
async function checkUptime() { | ||
try { | ||
const response = await fetch('https://api.hanswehr.com/root?root=qtl'); | ||
if (response.status === 200) { | ||
logger.info('Uptime check passed. Endpoint is up.'); | ||
email_sent = false | ||
} else { | ||
logger.error('Uptime check failed. Endpoint is down.'); | ||
// Trigger another workflow or take necessary actions on failure | ||
|
||
const subject = "API DOWN"; | ||
|
||
const mailOptions = { | ||
from: EMAIL_USERNAME, // Replace with your Gmail email | ||
to: EMAIL_LIST.join(", "), | ||
subject, | ||
text: subject, | ||
}; | ||
|
||
await transporter.sendMail(mailOptions); | ||
if (!email_sent) { | ||
await transporter.sendMail(mailOptions); | ||
email_sent = true | ||
} | ||
} | ||
} catch (error) { | ||
} catch (error: any) { | ||
logger.error(`Error checking uptime: ${error.message}`); | ||
if (!email_sent) { | ||
await transporter.sendMail(mailOptions); | ||
email_sent = true | ||
} | ||
// Trigger another workflow or take necessary actions on failure | ||
} | ||
} | ||
|
||
export const logHandler = router; | ||
export const logHandler = router; |