Skip to content

Commit

Permalink
Handle deployment agents
Browse files Browse the repository at this point in the history
  • Loading branch information
rushi committed Sep 2, 2024
1 parent 5c047e1 commit afe3f74
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
9 changes: 4 additions & 5 deletions config/default.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
{
"port": 3000,
"port": 6000,
"go": {
"url": "",
"username": "",
"password": "",
"jobs": {
"artifactName": ["testoutput"],
"artifactName": [
"testoutput"
],
"junitXmlFileName": [
"junit.xml",
"jscs.xml",
Expand All @@ -15,16 +17,13 @@
]
}
},

"slack": {
"token": "",
"signingSecret": ""
},

"jira": {
"url": ""
},

"whitelist": {
"emails": []
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "node src/index.js",
"dev": "nodemon --delay 3 --watch src src/index.js",
"format": "prettier --write ."
"format": "prettier -l --write src"
},
"devDependencies": {
"nodemon": "^3.1.4",
Expand Down
30 changes: 21 additions & 9 deletions src/handlers/AgentHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ class AgentHandler extends Handler {
async handle(request) {
const body = _.omit(request.body, ["operating_system"]);
const isElastic = body.is_elastic;
const isDeployAgent = !isElastic && !body.host_name.includes("i-");
const isDeployAgent = !isElastic && !body.host_name.includes("i-") && !body.host_name.startsWith("ip-");

const { host_name, agent_config_state, agent_state, build_state } = body;
const now = dayjs().format("YYYY-MM-DD HH:mm");
if (!isDeployAgent) {
return;
}

const agentName = isElastic ? host_name : chalk.green(host_name);
const configState = agent_config_state === "Disabled" ? chalk.bold(agent_config_state) : agent_config_state;
Expand All @@ -25,15 +28,11 @@ class AgentHandler extends Handler {

if (isDeployAgent) {
if (agent_state === "LostContact") {
console.log(
util.inspect(body, { colors: true, sorted: true, breakLength: 1000, depth: null, compact: true }),
);
console.log(chalk.bgRed.white(`[${now}] Non-Elastic Agent lost contact`));
AgentHandler.log(body);
console.log(chalk.bgRed.white(`[${now}] Deployment Agent lost contact`));
} else if (agent_state === "Idle" && build_state === "Idle") {
console.log(
util.inspect(body, { colors: true, sorted: true, breakLength: 1000, depth: null, compact: true }),
);
console.log(chalk.bgGreen.white(`[${now}] Non-Elastic Agent came online?`));
AgentHandler.log(body);
console.log(chalk.bgGreen.white(`[${now}] Deployment Agent came online?`));
}
}

Expand All @@ -42,6 +41,19 @@ class AgentHandler extends Handler {
console.log(" ".repeat(18), `https://sage.ci.xola.com/go/agents/${body.uuid}/job_run_history`);
}
}

static log(data, options = {}) {
console.log(
util.inspect(data, {
colors: true,
sorted: true,
breakLength: 1000,
depth: null,
compact: true,
...options,
}),
);
}
}

module.exports = AgentHandler;

0 comments on commit afe3f74

Please sign in to comment.