Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
check-validators-monitoring
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpdl-bloxberg
check-validators-monitoring
Commits
eb05384a
Commit
eb05384a
authored
4 years ago
by
kuzdogan
Browse files
Options
Downloads
Patches
Plain Diff
Send error email if fails
parent
29c6fa4a
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
.env-template
+4
-1
4 additions, 1 deletion
.env-template
contacts.js
+13
-6
13 additions, 6 deletions
contacts.js
email.js
+21
-1
21 additions, 1 deletion
email.js
index.js
+9
-4
9 additions, 4 deletions
index.js
with
47 additions
and
12 deletions
.env-template
+
4
−
1
View file @
eb05384a
...
...
@@ -2,3 +2,6 @@ SMTP_HOST=
SMTP_PORT=
SMTP_USER=
SMTP_PASS=
# set to development if developing.
# NODE_ENV=development
\ No newline at end of file
This diff is collapsed.
Click to expand it.
contacts.js
+
13
−
6
View file @
eb05384a
...
...
@@ -82,28 +82,35 @@ exports.getContactDetails = async (offlineValidatorsArray) => {
let
groupedTechies
=
groupContactsByInstitution
(
techies
);
let
groupedConsortium
=
groupContactsByInstitution
(
consortium
);
console
.
log
(
groupedTechies
)
let
noContacts
=
[]
for
(
validator
of
offlineValidatorsArray
)
{
let
address
=
validator
.
address
;
let
institution
=
addressInstitutionMap
[
address
];
logger
.
info
(
'
Processing contacts for institution with address
'
+
validator
.
address
+
'
and name
'
+
institution
)
let
contacts
;
// of this validator
// If there's a techie for the institution add them as contact
if
(
groupedTechies
[
institution
])
{
contacts
=
groupedTechies
[
institution
];
// ref not copy but OK
}
else
{
// all other contacts we have
contacts
=
groupedConsortium
[
institution
];
// ref not copy but OK
contacts
=
groupedTechies
[
institution
];
}
else
if
(
groupedConsortium
[
institution
])
{
// all other contacts we have
contacts
=
groupedConsortium
[
institution
];
}
else
{
// no contacts
noContacts
.
push
(
address
);
}
// Add address field to contact object
let
contactsWithAddress
=
contacts
.
map
(
contact
=>
{
let
contactsWithAddress
=
contacts
&&
contacts
.
map
(
contact
=>
{
// if contacts undefined, throw below.
return
{
address
:
address
,
lastOnline
:
validator
.
lastOnline
,
...
contact
}
})
result
.
push
(
contactsWithAddress
);
}
if
(
noContacts
.
length
>
0
)
throw
new
Error
(
'
Couldnt find contacts for addresses
'
+
noContacts
.
join
())
return
result
;
}
...
...
@@ -171,7 +178,7 @@ function mapAddressToInsitutions(contactsArray) {
for
(
contact
of
contactsArray
)
{
if
(
contact
.
haupt
===
'
H
'
&&
ethereumRegex
().
test
(
contact
.
comments
))
{
let
addr
=
contact
.
comments
.
match
(
ethereumRegex
());
result
[
addr
]
=
contact
.
institution
;
result
[
addr
]
=
contact
.
institution
;
// 0xEafe556569895f555755815131D21D49AFdb2Efe": "Universität Zürich"
}
}
return
result
;
...
...
This diff is collapsed.
Click to expand it.
email.js
+
21
−
1
View file @
eb05384a
...
...
@@ -34,6 +34,26 @@ exports.sendNoticeMails = (contactsArray) => {
return
Promise
.
all
(
promises
);
}
/**
* Function to send error emails to admins when the script fails.
*
* @param {Array} emails - array of email strings as receivers
* @param {Error} error - the thrown Error object
*/
exports
.
sendErrorEmails
=
(
emails
,
error
)
=>
{
const
message
=
{
from
:
`bloxberg Validator Monitoring <monitoring@bloxberg.org>`
,
to
:
emails
,
subject
:
'
❗ ERROR: bloxberg Validator Offline
'
,
text
:
`When running the script the following error is encountered\n\n
${
error
.
message
}
\n\n
${
error
.
stack
}
`
};
// return setTimeout(() => Promise.resolve(`Email sent to ${institution}: ${email}`), Math.random() * 1000 * 2) // Debug with randomly resolved Promises.
return
transport
.
sendMail
(
message
);
}
/**
* @function to send a notice email to the validator input.
*
...
...
This diff is collapsed.
Click to expand it.
index.js
+
9
−
4
View file @
eb05384a
const
{
getValidatorArray
}
=
require
(
'
./validators
'
);
const
{
sendNoticeMails
}
=
require
(
'
./email
'
);
const
{
sendNoticeMails
,
sendErrorEmails
}
=
require
(
'
./email
'
);
const
{
getContactDetails
}
=
require
(
'
./contacts
'
);
const
schedule
=
require
(
'
node-schedule
'
);
const
logger
=
require
(
'
./logger
'
);
const
ERROR_CONTACTS
=
[
'
lawton@mpdl.mpg.de
'
,
'
uzdogan@mpdl.mpg.de
'
]
// Set the schedule to run in cron format see helper https://crontab.guru/
// Format:
// minute hour day month day-of-week
...
...
@@ -13,9 +14,12 @@ const logger = require('./logger');
// 0 13 * * 1 ==> every Monday at 13:00
// 0 13 */5 * * ==> every fifth day of the month at 13:00 5th, 10th, 15th...
//
schedule
.
scheduleJob
(
'
0 13 * * 1
'
,
checkValidatorsAndSendEmails
);
if
(
process
.
env
.
NODE_ENV
===
'
development
'
)
{
// schedule.scheduleJob('*/5 * * * * *', () => logger.log('Hi'));
checkValidatorsAndSendEmails
()
}
else
{
schedule
.
scheduleJob
(
'
0 13 * * 1
'
,
checkValidatorsAndSendEmails
);
}
function
checkValidatorsAndSendEmails
()
{
getValidatorArray
()
...
...
@@ -30,5 +34,6 @@ function checkValidatorsAndSendEmails() {
.
catch
(
err
=>
{
logger
.
error
(
"
SOMETHING WENT WRONG
"
)
logger
.
error
(
err
)
sendErrorEmails
(
ERROR_CONTACTS
,
err
);
})
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment