• 0
Sign in to follow this  
Ben Tucker

Passing arguments to Groovy Script

Question

Can I pass host properties from the portal into a groovy script?

for example, in the \'\'Access remote servers via SSH session\'\' documentation example, the example code starts:

Line 1. import com.santaba.collector.groovyapi.expect.Expect

Line 2. cli = Expect.open(\'\'192.168.211.129\'\', \'\'root\'\', \'\'xxxxxxx\'\')

...

I\'d like to set some host parameters like

myservice.user = user

myservice.pass = 12345

and access them with something like the following:

Line 2. cli = Expect.open( some_hostname_variable , some_properties_map[\'\'myservice.user\'\'], some_properties_map[\'\'myservice.pass\'\'])

does some syntax like that exist? if so, where can I read more about it?

Share this post


Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Yes - see http://help.logicmonitor.com/using/datasource/creating-datasources/collectors/script-collector/groovy-support/rnSpecifically :rn

  • rn
  • Accessing all host properties - all properties of a host are accessible from groovy scripts via accessing the map hostProps.get(property). With other scripting languages, this requires passing in the properties as parameters. But in groovy, its as simple as accessing the hostname via: hostname = hostProps.get(system.hostname);rn

Share this post


Link to post
Share on other sites
  • 0

Ben, host properties are split into 2 groups: System properties, and custom properties.rnScreenshot: http://imageshack.us/f/545/sn8u.png/rnSystem properties can be referenced by hostProps.get(system.property) Where property is replaced by the specific property: location, ips, displayname, etc. i.e hostProps.get(system.ips)rn rnCustom properties are usually created with the property.name format. For example: snmp.community, wmi.user, etc; but you can specify the property name any way you like. When referencing the custom property just use the exact name of the property. i.e. hostProps.get(ssh.pass) assuming ssh.pass is specified as a custom property on the host.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this