Alive test argument via script

Hi All,

I am using command gmp.create_target in order to add targets to GVM.
Specifically I use command gmp.create_target(name=hostname, comment=comment, hosts=hostip, port_range=ports). At this point the command runs correctly.
Now, I need to add argument so the alive test will be set to Consider Alive. I tried adding at the end alive_test=‘Consider Alive’ but did not work.

Could you help me on how to set the argument?

I think it needs to be alive_tests with an s.

https://docs.greenbone.net/API/GMP/gmp-20.08.html#command_create_target

1 Like

Hi Steffen,
Thank you for your reply.

When I use “alive_tests”, I get error “TypeError: TargetsMixin.create_target() got an unexpected keyword argument ‘alive_tests’”
It is like the argument name “alive_tests” is not correct.
But, when I use the alive_test=‘Consider Alive’, I get error “gvm.errors.InvalidArgumentType: In create_target the argument alive_test must be of type AliveTest”
It seems that it understands the argument “alive_test”, but the value ‘Consider Alive’ is not correct.
Any other idea?

I just found the solution so I am putting it here in case anyone else has the same issue.
The correct argument is “alive_test” but the value of the argument needs to be an AliveTest enum instance (https://github.com/greenbone/python-gvm/issues/147).
According to documentation (https://python-gvm.readthedocs.io/en/latest/api/gmpv208.html) the method gvm.protocols.gmpv208.AliveTest(value) takes a string as input and returns an enum instance.

So what needs to be done is:
import gvm.protocols
myTest = gvm.protocols.gmpv208.AliveTest(‘Consider Alive’)
gmp.create_target(name=hostname, comment=comment, hosts=hostip, port_range=ports, alive_test=myTest)

2 Likes

I didn’t know you were using python-gvm. I’m glad you could fix your problem :slight_smile: