Skip to content
This repository has been archived by the owner on Apr 19, 2023. It is now read-only.

Commit

Permalink
✨ Add system info to test email, tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Sep 30, 2019
1 parent eddad77 commit 1df21aa
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 5 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "staart-manager",
"version": "1.1.32",
"version": "1.1.33",
"main": "index.js",
"repository": "[email protected]:AnandChowdhary/staart.git",
"author": "Anand Chowdhary <[email protected]>",
Expand Down Expand Up @@ -139,11 +139,12 @@
"response-time": "^2.3.2",
"slugify": "^1.3.5",
"snyk": "^1.228.5",
"stripe": "^7.9.1"
"stripe": "^7.9.1",
"systeminformation": "^4.14.8"
},
"files": [
"setup"
],
"snyk": true,
"staart-version": "1.1.32"
"staart-version": "1.1.33"
}
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,5 @@ export const ELASTIC_LOGS_PREFIX =
process.env.ELASTIC_LOGS_PREFIX || "staart-logs-";
export const ELASTIC_EVENTS_PREFIX =
process.env.ELASTIC_EVENTS_PREFIX || "staart-events-";
export const ELASTIC_INSTANCES_INDEX =
process.env.ELASTIC_INSTANCES_INDEX || "staart-instances";
19 changes: 18 additions & 1 deletion src/helpers/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ import {
AWS_ELASTIC_ACCESS_KEY,
AWS_ELASTIC_SECRET_KEY,
AWS_ELASTIC_REGION,
AWS_ELASTIC_HOST
AWS_ELASTIC_HOST,
ELASTIC_EVENTS_PREFIX,
ELASTIC_INSTANCES_INDEX
} from "../config";
import { ErrorCode } from "../interfaces/enum";
import { logError } from "./errors";
import { getSystemInformation } from "./utils";

AWS.config.update({
credentials: new AWS.Credentials(
Expand All @@ -22,6 +26,19 @@ export const elasticSearch = new Client({
connectionClass
});

getSystemInformation()
.then(body =>
elasticSearch.index({
index: ELASTIC_INSTANCES_INDEX,
body,
type: "log"
})
)
.then(() => {})
.catch(() =>
logError("ElasticSearch configuration error", "Unable to log event", 1)
);

export const cleanElasticSearchQueryResponse = (response: any) => {
if (response.hits && response.hits.hits) {
const count = response.hits.total;
Expand Down
15 changes: 14 additions & 1 deletion src/helpers/mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import Joi from "@hapi/joi";
import { joiValidate } from "./utils";
import { ErrorCode } from "../interfaces/enum";
import { logError } from "./errors";
import systemInfo from "systeminformation";
import pkg from "../../package.json";

const client = createClient({
key: SES_ACCESS,
Expand Down Expand Up @@ -91,7 +93,18 @@ sendMail({
from: SES_EMAIL,
to: TEST_EMAIL,
subject: "Test from Staart",
message: "This is an example email to test your Staart email configuration."
message: `This is an example email to test your Staart email configuration.\n\n${JSON.stringify(
{
time: systemInfo.time(),
package: {
name: pkg.name,
version: pkg.version,
repository: pkg.repository,
author: pkg.author,
"staart-version": pkg["staart-version"]
}
}
)}`
})
.then(() => {})
.catch(() =>
Expand Down
18 changes: 18 additions & 0 deletions src/helpers/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { isMatch } from "matcher";
import Hashids from "hashids/cjs";
import { getUserIdFromUsername } from "../crud/user";
import { HASH_IDS, HASH_ID_PREFIX } from "../config";
import systemInfo from "systeminformation";
import pkg from "../../package.json";

const hashIds = new Hashids(
HASH_IDS,
Expand Down Expand Up @@ -243,3 +245,19 @@ export const dnsResolve = (
resolve(records);
});
});

export const getSystemInformation = async () => {
return {
system: await systemInfo.system(),
time: systemInfo.time(),
cpu: await systemInfo.cpu(),
osInfo: await systemInfo.osInfo(),
package: {
name: pkg.name,
version: pkg.version,
repository: pkg.repository,
author: pkg.author,
"staart-version": pkg["staart-version"]
}
};
};
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7239,6 +7239,11 @@ symbol-tree@^3.2.2:
resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.4.tgz#430637d248ba77e078883951fb9aa0eed7c63fa2"
integrity sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==

systeminformation@^4.14.8:
version "4.14.8"
resolved "https://registry.yarnpkg.com/systeminformation/-/systeminformation-4.14.8.tgz#ebb9580e4da98daf438839e65b9c29d9869226a6"
integrity sha512-05wW1YaMBI6LlVtvw2wXQGr0thpX8E0IImYcpbqUiNanfmq8e+V89pDW2L5V/mN8kU37W0VtVySftQ0PwMIXKw==

tar@^4:
version "4.4.10"
resolved "https://registry.yarnpkg.com/tar/-/tar-4.4.10.tgz#946b2810b9a5e0b26140cf78bea6b0b0d689eba1"
Expand Down

0 comments on commit 1df21aa

Please sign in to comment.