Skip to content

Commit

Permalink
Merge pull request #352 from erwindon/connected2
Browse files Browse the repository at this point in the history
use salt-api to determine connected minions
  • Loading branch information
erwindon authored Feb 7, 2021
2 parents 16f9592 + 5847101 commit e63a19e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
8 changes: 8 additions & 0 deletions saltgui/static/scripts/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,14 @@ export class API {
return this.apiRequest("POST", "/", params);
}

getWheelMinionsConnected () {
const params = {
"client": "wheel",
"fun": "minions.connected"
};
return this.apiRequest("POST", "/", params);
}

getStats () {
const params = {
};
Expand Down
33 changes: 33 additions & 0 deletions saltgui/static/scripts/panels/Minions.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class MinionsPanel extends Panel {

onShow () {
const wheelKeyListAllPromise = this.api.getWheelKeyListAll();
const wheelMinionsConnectedPromise = this.api.getWheelMinionsConnected();
const localGrainsItemsPromise = this.api.getLocalGrainsItems(null);
const runnerManageVersionsPromise = this.api.getRunnerManageVersions();

Expand All @@ -37,6 +38,14 @@ export class MinionsPanel extends Panel {
wheelKeyListAllPromise.then((pWheelKeyListAllData) => {
this._handleMinionsWheelKeyListAll(pWheelKeyListAllData);

wheelMinionsConnectedPromise.then((pWheelMinionsConnectedData) => {
this._handlewheelMinionsConnected(pWheelMinionsConnectedData);
return true;
}, (getWheelMinionsConnectedMsg) => {
console.log("getWheelMinionsConnectedMsg", getWheelMinionsConnectedMsg);
return false;
});

localGrainsItemsPromise.then((pLocalGrainsItemsData) => {
this.updateMinions(pLocalGrainsItemsData);
return true;
Expand Down Expand Up @@ -92,6 +101,30 @@ export class MinionsPanel extends Panel {
this.setMsg(txt);
}

_handlewheelMinionsConnected (pWheelMinionsConnectedData) {
if (this.showErrorRowInstead(pWheelMinionsConnectedData)) {
return;
}

const minionIds = pWheelMinionsConnectedData.return[0].data.return;

for (const tr of this.table.tBodies[0].childNodes) {
if (minionIds.indexOf(tr.dataset.minionId) >= 0) {
// skip the connected minions
continue;
}
const statusTd = tr.querySelector("td.status");
if (!statusTd) {
continue;
}
// this is the initial warning only
// it will potentially be replaced by a less aggressive warning
// when the grains information is returned
statusTd.innerText = "offline";
statusTd.classList.add("offline");
}
}

updateOfflineMinion (pMinionId, pMinionsDict) {
super.updateOfflineMinion(pMinionId, pMinionsDict);

Expand Down
7 changes: 5 additions & 2 deletions saltgui/static/scripts/panels/Panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export class Panel {

minionTr = document.createElement("tr");
minionTr.id = Utils.getIdFromMinionId(pMinionId);
minionTr.dataset.minionId = pMinionId;

minionTr.appendChild(Utils.createTd("minion-id", pMinionId));

Expand Down Expand Up @@ -577,12 +578,14 @@ export class Panel {
if (pMinionId in pMinionsDict) {
if (pMinionsDict[pMinionId] === "true") {
Utils.addToolTip(offlineSpan, "Minion is offline\nIs the host running and is the salt-minion installed and started?\nUpdate file 'minions.txt' when needed", "bottom-left");
offlineSpan.style.color = "red";
offlineSpan.classList.add("offline");
} else {
Utils.addToolTip(offlineSpan, "Minion is offline\nSince it is reported as inactive in file 'minions.txt', that should be OK", "bottom-left");
offlineSpan.classList.remove("offline");
}
} else {
offlineSpan.classList.add("offline");
}
offlineSpan.classList.add("offline");
const offlineTd = Utils.createTd();
offlineTd.appendChild(offlineSpan);
minionTr.appendChild(offlineTd);
Expand Down
4 changes: 4 additions & 0 deletions saltgui/static/stylesheets/page.css
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ table tr td:last-of-type {
color: #00f;
}

.offline {
color: red;
}

.osimage {
max-width: 18px;
max-height: 18px;
Expand Down

0 comments on commit e63a19e

Please sign in to comment.