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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mpdl-bloxberg
check-validators-monitoring
Commits
d6f2af9c
Commit
d6f2af9c
authored
Jan 19, 2021
by
kuzdogan
Browse files
Options
Downloads
Patches
Plain Diff
Avoid crash and notice not found contacts to admins
parent
eb05384a
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
contacts.js
+14
-14
14 additions, 14 deletions
contacts.js
email.js
+28
-0
28 additions, 0 deletions
email.js
index.js
+7
-4
7 additions, 4 deletions
index.js
logger.js
+1
-1
1 addition, 1 deletion
logger.js
with
50 additions
and
19 deletions
contacts.js
+
14
−
14
View file @
d6f2af9c
...
@@ -73,7 +73,7 @@ const logger = require('./logger');
...
@@ -73,7 +73,7 @@ const logger = require('./logger');
*/
*/
exports
.
getContactDetails
=
async
(
offlineValidatorsArray
)
=>
{
exports
.
getContactDetails
=
async
(
offlineValidatorsArray
)
=>
{
logger
.
log
(
'
Offline validators are:
'
,
offlineValidatorsArray
);
logger
.
log
(
'
Offline validators are:
'
,
offlineValidatorsArray
);
let
result
=
[];
let
offlineContacts
=
[];
// Prepare data
// Prepare data
let
techies
=
await
readCSVtoJson
(
TECHIE_FILE
);
let
techies
=
await
readCSVtoJson
(
TECHIE_FILE
);
...
@@ -83,7 +83,7 @@ exports.getContactDetails = async (offlineValidatorsArray) => {
...
@@ -83,7 +83,7 @@ exports.getContactDetails = async (offlineValidatorsArray) => {
let
groupedConsortium
=
groupContactsByInstitution
(
consortium
);
let
groupedConsortium
=
groupContactsByInstitution
(
consortium
);
console
.
log
(
groupedTechies
)
console
.
log
(
groupedTechies
)
let
noContacts
=
[]
let
no
tFound
Contacts
=
[]
for
(
validator
of
offlineValidatorsArray
)
{
for
(
validator
of
offlineValidatorsArray
)
{
let
address
=
validator
.
address
;
let
address
=
validator
.
address
;
let
institution
=
addressInstitutionMap
[
address
];
let
institution
=
addressInstitutionMap
[
address
];
...
@@ -96,22 +96,22 @@ exports.getContactDetails = async (offlineValidatorsArray) => {
...
@@ -96,22 +96,22 @@ exports.getContactDetails = async (offlineValidatorsArray) => {
}
else
if
(
groupedConsortium
[
institution
])
{
// all other contacts we have
}
else
if
(
groupedConsortium
[
institution
])
{
// all other contacts we have
contacts
=
groupedConsortium
[
institution
];
contacts
=
groupedConsortium
[
institution
];
}
else
{
// no contacts
}
else
{
// no contacts
noContacts
.
push
(
address
);
no
tFound
Contacts
.
push
(
{
institution
,
address
}
);
}
}
// Add address field to contact object
// Add address field to contact object
let
contactsWithAddress
=
contacts
&&
contacts
.
map
(
contact
=>
{
// if contacts undefined, throw below.
if
(
contacts
)
{
let
contactsWithAddress
=
contacts
.
map
(
contact
=>
{
// if contacts undefined, throw below.
return
{
return
{
address
:
address
,
address
:
address
,
lastOnline
:
validator
.
lastOnline
,
lastOnline
:
validator
.
lastOnline
,
...
contact
...
contact
}
}
})
})
result
.
push
(
contactsWithAddress
);
offlineContacts
.
push
(
contactsWithAddress
);
}
}
if
(
noContacts
.
length
>
0
)
}
throw
new
Error
(
'
Couldnt find contacts for addresses
'
+
noContacts
.
join
())
return
{
offlineContacts
,
notFoundContacts
};
return
result
;
}
}
/**
/**
...
...
...
...
This diff is collapsed.
Click to expand it.
email.js
+
28
−
0
View file @
d6f2af9c
...
@@ -41,6 +41,7 @@ exports.sendNoticeMails = (contactsArray) => {
...
@@ -41,6 +41,7 @@ exports.sendNoticeMails = (contactsArray) => {
* @param {Error} error - the thrown Error object
* @param {Error} error - the thrown Error object
*/
*/
exports
.
sendErrorEmails
=
(
emails
,
error
)
=>
{
exports
.
sendErrorEmails
=
(
emails
,
error
)
=>
{
logger
.
log
(
'
Sending error emails to
'
+
emails
.
join
()
+
'
about:
'
+
error
)
const
message
=
{
const
message
=
{
from
:
`bloxberg Validator Monitoring <monitoring@bloxberg.org>`
,
from
:
`bloxberg Validator Monitoring <monitoring@bloxberg.org>`
,
to
:
emails
,
to
:
emails
,
...
@@ -54,6 +55,33 @@ exports.sendErrorEmails = (emails, error) => {
...
@@ -54,6 +55,33 @@ exports.sendErrorEmails = (emails, error) => {
return
transport
.
sendMail
(
message
);
return
transport
.
sendMail
(
message
);
}
}
/**
* 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
.
sendNotFoundEmails
=
(
emails
,
notFoundContacts
)
=>
{
logger
.
log
(
'
Sending not found emails to
'
+
emails
.
join
()
+
'
for the addresses:
'
+
notFoundContacts
.
map
(
contact
=>
contact
.
address
).
join
())
const
message
=
{
from
:
`bloxberg Validator Monitoring <monitoring@bloxberg.org>`
,
to
:
emails
,
subject
:
'
❗ Contact Not Found: bloxberg Validator Offline
'
,
text
:
`The following validators do not have an assigned contact and
hence were not able to be contacted. If the institution name is undefined,
it means an associated institution for the address couldn't be found in Cobra input.
Otherwise the institution has an associated address but is missing any contacts. \n\n`
+
notFoundContacts
.
map
(
contact
=>
{
return
`Institution:
${
contact
.
institution
}
\n\n
Address:
${
contact
.
address
}
\n\n`
}).
join
()
};
// 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.
* @function to send a notice email to the validator input.
*
*
...
...
...
...
This diff is collapsed.
Click to expand it.
index.js
+
7
−
4
View file @
d6f2af9c
const
{
getValidatorArray
}
=
require
(
'
./validators
'
);
const
{
getValidatorArray
}
=
require
(
'
./validators
'
);
const
{
sendNoticeMails
,
sendErrorEmails
}
=
require
(
'
./email
'
);
const
{
sendNoticeMails
,
sendErrorEmails
,
sendNotFoundEmails
}
=
require
(
'
./email
'
);
const
{
getContactDetails
}
=
require
(
'
./contacts
'
);
const
{
getContactDetails
}
=
require
(
'
./contacts
'
);
const
schedule
=
require
(
'
node-schedule
'
);
const
schedule
=
require
(
'
node-schedule
'
);
const
logger
=
require
(
'
./logger
'
);
const
logger
=
require
(
'
./logger
'
);
...
@@ -28,12 +28,15 @@ function checkValidatorsAndSendEmails() {
...
@@ -28,12 +28,15 @@ function checkValidatorsAndSendEmails() {
logger
.
log
(
"
Got the online status for validators:
"
);
logger
.
log
(
"
Got the online status for validators:
"
);
return
getContactDetails
(
offlineValidatorsArray
);
return
getContactDetails
(
offlineValidatorsArray
);
})
})
.
then
(
offlineContacts
=>
{
.
then
(({
offlineContacts
,
notFoundContacts
})
=>
{
return
sendNoticeMails
(
offlineContacts
);
return
Promise
.
all
([
sendNoticeMails
(
offlineContacts
),
sendNotFoundEmails
(
ERROR_CONTACTS
,
notFoundContacts
)
]);
})
})
.
catch
(
err
=>
{
.
catch
(
err
=>
{
logger
.
error
(
"
SOMETHING WENT WRONG
"
)
logger
.
error
(
"
SOMETHING WENT WRONG
"
)
logger
.
error
(
err
)
logger
.
error
(
err
.
stack
)
sendErrorEmails
(
ERROR_CONTACTS
,
err
);
sendErrorEmails
(
ERROR_CONTACTS
,
err
);
})
})
}
}
This diff is collapsed.
Click to expand it.
logger.js
+
1
−
1
View file @
d6f2af9c
...
@@ -19,7 +19,7 @@ const fileLogOptions = {
...
@@ -19,7 +19,7 @@ const fileLogOptions = {
const
mainLoggers
=
logger
.
createLogger
({
const
mainLoggers
=
logger
.
createLogger
({
level
:
'
info
'
,
level
:
'
info
'
,
format
:
format
.
combine
(
format
:
format
.
combine
(
format
.
metadata
({
fillExcept
:
[
'
timestamp
'
,
'
level
'
,
'
message
'
]
})
format
.
metadata
({
fillExcept
:
[
'
timestamp
'
,
'
level
'
,
'
message
'
,
'
stack
'
]
})
),
),
transports
:
[
transports
:
[
new
transports
.
DailyRotateFile
({
new
transports
.
DailyRotateFile
({
...
...
...
...
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
sign in
to comment