Add configuration policy monitors and action picker for computers
Configuration policies need a way to attach process/service monitors so drift can be evaluated against a machine's desired state. This wires the policy resolver and routes to the shared monitor catalog and adds an action picker UI that can create process monitors with an optional launch path.
This commit is contained in:
@@ -166,3 +166,61 @@ def effective_policy_for(assetid):
|
||||
|
||||
business_policies = BusinessPolicy.query.filter_by(isactive=True).all()
|
||||
return build_effective_policy(computer, business_policies)
|
||||
|
||||
|
||||
def _monitor_action_ids(effective):
|
||||
"""Extract attached monitor ids from an EffectivePolicy's action names.
|
||||
|
||||
Monitor attachment rides the policy layer as an action named
|
||||
'monitor:<endpointmonitorid>' (see plugins/endpoints/commands.py). This
|
||||
reads those ids back out of a resolved policy so a caller can turn them into
|
||||
concrete monitor definitions.
|
||||
"""
|
||||
ids = set()
|
||||
for name in effective.allowed_actions():
|
||||
if isinstance(name, str) and name.startswith('monitor:'):
|
||||
raw = name[len('monitor:'):]
|
||||
try:
|
||||
ids.add(int(raw))
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
return ids
|
||||
|
||||
|
||||
def monitor_ids_for_asset(assetid):
|
||||
"""Set of endpointmonitorids attached to an endpoint by effective policy."""
|
||||
return _monitor_action_ids(effective_policy_for(assetid))
|
||||
|
||||
|
||||
def monitor_ids_for_pctype(computertypeid):
|
||||
"""Set of endpointmonitorids attached to a PC type by effective policy.
|
||||
|
||||
Folds active Business Policies against a synthetic context carrying only the
|
||||
PC type (no installed apps), which is what the agent runtime-fetch path needs
|
||||
when it resolves its monitor set by type rather than by a specific asset.
|
||||
Returns an empty set when the policy feature is off.
|
||||
"""
|
||||
from ..policyflag import policy_flag_enabled
|
||||
if not policy_flag_enabled():
|
||||
return set()
|
||||
|
||||
from ..models import BusinessPolicy
|
||||
|
||||
context = {'computertypeid': computertypeid, 'appids': set()}
|
||||
business_policies = BusinessPolicy.query.filter_by(isactive=True).all()
|
||||
resolved = {}
|
||||
for businesspolicyid, config_policy in _iter_matching_configpolicies(
|
||||
business_policies, context):
|
||||
for action_row in config_policy.actions:
|
||||
if not action_row.isactive:
|
||||
continue
|
||||
resolved.setdefault(action_row.action, True)
|
||||
ids = set()
|
||||
for name in resolved:
|
||||
if isinstance(name, str) and name.startswith('monitor:'):
|
||||
raw = name[len('monitor:'):]
|
||||
try:
|
||||
ids.add(int(raw))
|
||||
except (TypeError, ValueError):
|
||||
continue
|
||||
return ids
|
||||
|
||||
Reference in New Issue
Block a user