Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial PoC for stats module to handle risk-related items #7

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
6519eef
initial PoC for stats module to handle risk-related items
praetorian-matt-schneider Nov 17, 2024
9478ff9
removes breakpoints
praetorian-matt-schneider Nov 17, 2024
c0e2cdf
Add capabilities option to job add (#8)
praetorian-harry Nov 22, 2024
f884186
added a check for new release, similar to how 'pip' urges people to u…
peter-kwan Nov 23, 2024
dcf0054
adds assets to stats
praetorian-matt-schneider Dec 6, 2024
4f5b88f
adds seeds
praetorian-matt-schneider Dec 6, 2024
12f1d2a
add profile to the end-to-end tests (#12)
peter-kwan Dec 13, 2024
e0165a7
Fix seeds search (#13)
peter-kwan Dec 13, 2024
d2c50c7
output version check to stderr (#11)
praetorian-matt-schneider Dec 13, 2024
99f7985
updates webhook to use current_principal instead of user to avoid acc…
praetorian-matt-schneider Dec 13, 2024
b72ee29
rev up to 1.5.5 (#14)
peter-kwan Dec 13, 2024
865c747
Fix end-to-end search test; also increase max page number (#15)
peter-kwan Dec 13, 2024
cbe6484
add option to read username and password from environment variables (…
peter-kwan Dec 17, 2024
7924319
added support for seed CRUD (#17)
peter-kwan Dec 24, 2024
ad4cf91
Added support for updating attributes (#18)
peter-kwan Dec 24, 2024
3faa945
added AL, FL, and PL for seed status (#19)
peter-kwan Dec 27, 2024
e827d6f
add attribute statuses (#20)
josephwhenry Dec 30, 2024
819d68e
initial PoC for stats module to handle risk-related items
praetorian-matt-schneider Nov 17, 2024
084df21
adds assets to stats
praetorian-matt-schneider Dec 6, 2024
4199d54
adds seeds
praetorian-matt-schneider Dec 6, 2024
130bf50
Merge branch 'statistics' of github.com:praetorian-matt-schneider/pra…
praetorian-matt-schneider Jan 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adds assets to stats
  • Loading branch information
praetorian-matt-schneider committed Dec 6, 2024
commit dcf0054ae8e2972e5371bd90e5304368e726dce6
4 changes: 3 additions & 1 deletion praetorian_cli/handlers/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ def stats(chariot, filter, from_date, to_date, details, offset, page, help_stats
# Map common filter aliases to StatsFilter values
filter_map = {
'risks': chariot.stats.util.RISKS,
'risk_events': chariot.stats.util.RISK_EVENTS
'risk_events': chariot.stats.util.RISK_EVENTS,
'assets_by_status': chariot.stats.util.ASSETS_BY_STATUS,
'assets_by_class': chariot.stats.util.ASSETS_BY_CLASS
}

# Use mapped filter if available, otherwise use raw filter string
Expand Down
21 changes: 21 additions & 0 deletions praetorian_cli/sdk/entities/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@ class StatsUtil:
# Main categories
RISKS = "my#status" # Risk statistics by status/severity
RISK_EVENTS = "event#risk" # Risk event statistics
ASSETS_BY_STATUS = "asset#status" # Asset statistics by status - NOTE this is just to differentiate from RISKS; the actual prefix is the same
ASSETS_BY_CLASS = "class##asset##" # Asset statistics by class

# All possible risk statuses
RISK_STATUSES = ["T", "O", "R", "I", "D"]

# All possible asset statuses
ASSET_STATUSES = ["A", "P", "D", "F", "AL", "AH"]

@staticmethod
def risks_by_status(status=None, severity=None):
"""Build filter for risk statistics by status and/or severity"""
Expand All @@ -27,13 +32,20 @@ def get_statistics_help():
--filter risks : All risk statistics
--filter risk_events : All risk event statistics
--filter "my#status:O#H" : Open high severity risks

2. Assets:
--filter assets_by_status : All asset statistics by status (A,P,D,F,AL,AH)
--filter assets_by_class : All asset statistics by class

Examples:
1. Current risk counts:
$ chariot list statistics --filter risks --to now

2. Risk event history:
$ chariot list statistics --filter risk_events --from 2024-01-01

3. Current asset status:
$ chariot list statistics --filter assets_by_status --to now
"""

class Stats:
Expand All @@ -57,6 +69,15 @@ def list(self, prefix_filter='', from_date=None, to_date=None, offset=None, page
elif prefix_filter == self.util.RISK_EVENTS:
# events require double pounds before event type
return self._query_single("event##risk#", from_date, to_date, offset, pages)
elif prefix_filter == self.util.ASSETS_BY_STATUS:
all_stats = []
for status in self.util.ASSET_STATUSES:
asset_filter = f"my#status:{status}"
stats, _ = self._query_single(asset_filter, from_date, to_date, offset, pages)
all_stats.extend(stats)
return all_stats, None
elif prefix_filter == self.util.ASSETS_BY_CLASS:
return self._query_single("class##asset#", from_date, to_date, offset, pages)
else:
return self._query_single(prefix_filter, from_date, to_date, offset, pages)

Expand Down