Skip to content

Commit

Permalink
feat: add debug logging and improve error handling
Browse files Browse the repository at this point in the history
- add debug statements for severity counts, limits and threshold checks
- improve error handling for API request failures
- refactor threshold checking logic
- add more detailed output for threshold violations
  • Loading branch information
scriptprivate authored Aug 12, 2024
1 parent 3176d92 commit 36ca311
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions security-gate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,29 @@ sub main {

print "\n";

print "Debug: Severity counts: " . join(", ", map {"$_: $severity_counts{$_}"} @severities) . "\n";
print "Debug: Severity limits: " . join(", ", map {"$_: $severity_limits{$_}"} @severities) . "\n";

my $threshold_exceeded = 0;
foreach my $severity (@severities) {
print "Debug: Checking $severity - Count: $severity_counts{$severity}, Limit: $severity_limits{$severity}\n";
if ($severity_counts{$severity} > $severity_limits{$severity}) {
print "[+] More than $severity_limits{$severity} $severity security alerts found. Finalizing the process with error.\n";
return 1;
print "[+] More than $severity_limits{$severity} $severity security alerts found.\n";
$threshold_exceeded = 1;
}
}

print "Debug: Threshold exceeded: $threshold_exceeded\n";

if ($threshold_exceeded) {
print "Finalizing the process with error.\n";
return 1;
}
}

else {
print "Error: Unable to fetch alerts. HTTP status code: " . $request->code() . "\n";
return 1;
}

return 0;
Expand All @@ -89,7 +106,8 @@ sub main {

if ($ENV{TEST_MODE}) {
main();
}
}

else {
exit main();
}

0 comments on commit 36ca311

Please sign in to comment.