Gvm-tools Pyshell Create Schedule TimeUnit

Hey everyone,

I appreciate the help. I am learning to script out the creation of a task and am working on creating the schedules. When I select a period_unit I am given an error. I have tried every variation of the word “week” and it still throws an error.

>>> gmp.create_schedule(name='TestSchedule',first_time_hour=5,first_time_minute=1,first_time_month=5,first_time_day_of_month=15,first_time_year=2020,period=1,period_unit='WEEK')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/gvm/protocols/gmpv7/__init__.py", line 1663, in create_schedule
    arg_type=TimeUnit.__name__,
gvm.errors.InvalidArgumentType: In create_schedule the argument period_unit must be of type TimeUnit.
>>> gmp.create_schedule(name='TestSchedule',first_time_hour=5,first_time_minute=1,first_time_month=5,first_time_day_of_month=15,first_time_year=2020,period=1,period_unit=WEEK)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
NameError: name 'WEEK' is not defined
>>> gmp.create_schedule(name='TestSchedule',first_time_hour=5,first_time_minute=1,first_time_month=5,first_time_day_of_month=15,first_time_year=2020,period=1,period_unit='WEEK')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/gvm/protocols/gmpv7/__init__.py", line 1663, in create_schedule
    arg_type=TimeUnit.__name__,
gvm.errors.InvalidArgumentType: In create_schedule the argument period_unit must be of type TimeUnit.
>>> gmp.create_schedule(name='TestSchedule',first_time_hour=5,first_time_minute=1,first_time_month=5,first_time_day_of_month=15,first_time_year=2020,period=1,period_unit=gmp.week)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'Gmp' object has no attribute 'week'
>>> gmp.create_schedule(name='TestSchedule',first_time_hour=5,first_time_minute=1,first_time_month=5,first_time_day_of_month=15,first_time_year=2020,period=1,period_unit='week')
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.7/dist-packages/gvm/protocols/gmpv7/__init__.py", line 1663, in create_schedule
    arg_type=TimeUnit.__name__,
gvm.errors.InvalidArgumentType: In create_schedule the argument period_unit must be of type TimeUnit.

Thank you very much in advance!

If you take a look at the docs (or the treaceback) the create_schedule method expects a TimeUnit enum instance and not a string. Should be available as gmp.types.TimeUnit.

1 Like

@bricks Thank you for the assistance.

For anyone else looking for how to use this it is:

gmp.types.TimeUnit.WEEK

In my scripts I will probably set a global var for:

week = gmp.types.TimeUnit.WEEK

or some such.

Thanks for the assistance!

1 Like