fix(sentinelone): count-agents can be asked about the whole fleet again
Declared as a boolean, isActive rendered as a checkbox in the toolbox, and a checkbox has no empty state: the count was forced to one half of the fleet or the other, with no way to ask for both. As text, an empty field means the filter is not sent. true/yes/1 and false/no/0 are read in any case, a real JSON boolean from a playbook still works, and anything else is refused rather than folded into false — that would answer a different question than the one asked.
This commit is contained in:
@@ -13,6 +13,10 @@ def csv(v):
|
||||
return [x.strip() for x in str(v or "").split(",") if x.strip()]
|
||||
|
||||
|
||||
TRUE_WORDS = {"true", "yes", "1"}
|
||||
FALSE_WORDS = {"false", "no", "0"}
|
||||
|
||||
|
||||
def main():
|
||||
secrets = json.loads(os.environ.get("INTEGRATION_SECRETS", "{}"))
|
||||
inputs = json.loads(os.environ.get("INTEGRATION_INPUTS", "{}"))
|
||||
@@ -40,10 +44,15 @@ def main():
|
||||
"operationalStatesNin": ",".join(csv(inputs.get("operationalStatesNin"))),
|
||||
"machineTypes": ",".join(csv(inputs.get("machineTypes"))),
|
||||
}
|
||||
# Only sent when the caller actually set it: an unset boolean must not become
|
||||
# isActive=false and quietly count the inactive agents instead of all of them.
|
||||
if inputs.get("isActive") not in (None, ""):
|
||||
qs["isActive"] = "true" if inputs["isActive"] in (True, "true", "True", 1, "1") else "false"
|
||||
# Text rather than a checkbox, which has no empty state: left blank the filter
|
||||
# is not sent at all and the count covers active and inactive agents alike.
|
||||
# A value we cannot read is refused rather than folded into false, which would
|
||||
# answer a different question than the one asked.
|
||||
active = str(inputs.get("isActive", "")).strip().lower()
|
||||
if active:
|
||||
if active not in TRUE_WORDS | FALSE_WORDS:
|
||||
raise ValueError("isActive must be true or false, got: " + repr(inputs["isActive"]))
|
||||
qs["isActive"] = "true" if active in TRUE_WORDS else "false"
|
||||
url = base + "/agents/count?" + urllib.parse.urlencode({k: v for k, v in qs.items() if v not in (None, "")})
|
||||
print(json.dumps(request("GET", url, headers)))
|
||||
# === END ===
|
||||
|
||||
Reference in New Issue
Block a user