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

create_scan_schedule adds 30 minutes #708

Open
dworkman1 opened this issue Jun 19, 2023 · 1 comment
Open

create_scan_schedule adds 30 minutes #708

dworkman1 opened this issue Jun 19, 2023 · 1 comment
Labels
bug This is a bug with the pyTenable library Tenable.io Tenable.io Package

Comments

@dworkman1
Copy link

Describe the bug
When calling create_scan_schedule the code logic is adding 30 minutes based on the lines below in https://github.com/tenable/pyTenable/blob/master/tenable/io/scans.py (Lines: 300 and 301)

secs = timedelta(minutes=30).total_seconds()
starttime = datetime.fromtimestamp(starttime.timestamp() + secs - starttime.timestamp() % secs)

I believe these lines should be:

secs = timedelta(minutes=30).total_seconds()
starttime = datetime.fromtimestamp(starttime.timestamp() - starttime.timestamp() % secs)

Or if you want to simulate classic rounding:

secs = timedelta(minutes=30).total_seconds()
secs_from_last_interval =  starttime.timestamp() % secs
if secs_from_last_interval < secs/2
   starttime = datetime.fromtimestamp(starttime.timestamp() - starttime.timestamp() % secs)
else:
  starttime = datetime.fromtimestamp(starttime.timestamp() + (secs - starttime.timestamp() % secs)

To Reproduce
Steps to reproduce the behavior:

def create_scan_schedule(scan_schedule, tenable_connector):
    #Initializing Function Scope
    frequency = scan_schedule.get("frequency")
    starttime_string = scan_schedule.get("starttime")
    scan_schedule.setdefault('timezone', 'US/Eastern')

    if frequency and starttime_string:
        scan_schedule['starttime'] = datetime.strptime(starttime_string, '%Y-%m-%d %H:%M:%S')
        scan_schedule_object = tenable_connector.scans.create_scan_schedule(**scan_schedule)
        return scan_schedule_object
    else:
        return {}

with scan_schedule set to a dict:

{
                "enabled": true,
                "frequency": "ONETIME",
                "interval": 1,
                "starttime": "2023-06-19 20:00:00"
}

Expected behavior
starttime should be set to the last 30 minutes not 30 minutes beyond.

@dworkman1
Copy link
Author

Just to confirm I am seeing a starttime of "2023-06-19 20:30:00" when I run your code.

@aseemsavio aseemsavio added bug This is a bug with the pyTenable library Tenable.io Tenable.io Package labels Jun 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This is a bug with the pyTenable library Tenable.io Tenable.io Package
Projects
None yet
Development

No branches or pull requests

2 participants