Fixed so that hash adding for local approval should happen sooner if device is moved out of OTP early. Also minor fixes with timestamping of hash additon to use local time instead of epoch, and str matching for local approval allow list finding
This commit is contained in:
+12
-7
@@ -3,13 +3,12 @@ import requests
|
||||
import os
|
||||
import pandas as pd
|
||||
import utils.pretty as ct
|
||||
import shutil
|
||||
import math
|
||||
import time
|
||||
import utils.clientfunctions as clientf
|
||||
import utils.pathfunctions as pathf
|
||||
import utils.policyfunctions as policyf
|
||||
from utils.perstscheduler import register_function, run_once_job, recurring_job, reload_jobs, start_scheduler
|
||||
from utils.perstscheduler import register_function, run_once_job, recurring_job, reload_jobs, start_scheduler, find_and_prioritize_jobs_by_pid
|
||||
|
||||
def getActiveOTP(url):
|
||||
|
||||
@@ -30,7 +29,7 @@ def getActiveOTP(url):
|
||||
os.remove("OTP\\PARQ\\newest_active_OTP.parquet")
|
||||
otp.to_parquet("OTP\\PARQ\\newest_active_OTP.parquet", index=False)
|
||||
if not otp.empty:
|
||||
ct.style_dataframe_dark(otp, f"newest_active_OTP.html")
|
||||
ct.style_dataframe_dark(otp, f"OTP\\HTML\\newest_active_OTP.html")
|
||||
|
||||
def getOTPActivities(url, otpid):
|
||||
endpoint = url + f'/v1/otp/activities'
|
||||
@@ -92,9 +91,9 @@ def monitorOTP(url, pups):
|
||||
hostname = row['hostname']
|
||||
purpose = row ['purpose']
|
||||
pid = row['otpid']
|
||||
early = math.floor(duration * .9)
|
||||
early = math.floor(duration * .95)
|
||||
#If newly added to the list - schedule adding the majority of the executions prior to the expiration of OTP period.
|
||||
run_once_job(f"Add activity hashes for {pid}, for {hostname} for the purpose: {purpose}, early run", "addhash", time.time() + early, [url, clientid, pid, pups], None)
|
||||
run_once_job(f"Add activity hashes for {pid}, for {hostname} for the purpose: {purpose}", "addhash", time.time() + early, [url, clientid, pid, pups], None)
|
||||
print(f"Processing: {pid} with other data: {row}")
|
||||
|
||||
|
||||
@@ -110,14 +109,20 @@ def monitorOTP(url, pups):
|
||||
pid = row['otpid']
|
||||
allowlist = clientf.getDestAllowlistFromClientID(url,clientid)
|
||||
policy = clientf.getPolicyFromClientID(url,clientid)
|
||||
#When duration completes -
|
||||
|
||||
"""
|
||||
Devices can come out of OTP either by timeout, or by early move out of OTP. If they are manually moved out prior to the job to add hashes can run, we want to accelerate the job.
|
||||
But first, we want to update the OTP activities one final time for the pid, then move up any jobs if they exist, then add the hashes to the local approval allowlist
|
||||
"""
|
||||
|
||||
getOTPActivities(url,pid)
|
||||
find_and_prioritize_jobs_by_pid(pid, 1)
|
||||
addOTPHashes(url, clientid,pid, pups)
|
||||
|
||||
finalhashesadded = pd.read_parquet(f"OTP\\PARQ\\otp_activities_{pid}.parquet")
|
||||
finalhashesadded['policy'] = policy
|
||||
finalhashesadded['allowlist'] = allowlist
|
||||
finalhashesadded['added_at'] = time.time()
|
||||
finalhashesadded['added_at'] = time.localtime()
|
||||
|
||||
if not os.path.exists(f"OTP\\PARQ\\localapprovalhistory.parquet"):
|
||||
df = pd.DataFrame()
|
||||
|
||||
Reference in New Issue
Block a user