Calling script include from "scripts - background"

Peter Farr
Giga Contributor

I am trying to test a script include by calling it from Scripts - Background but it is apparently not working for me. I am not sure what it wrong. I have inserted a log call into the top of the script include which should execute as soon as the function is called. Here is the top of the include:

var Rapid7CILookup = Class.create();
Rapid7CILookup.prototype = {
    initialize: function(domain) {
        if (domain)
            this.domain = domain;
        else
            this.domain = "global";
    },
    
    lookupCI: function(source) {
        var status = '';
	gs.log("***I am here***");
<SNIP>

And here is how I am calling it:

var new_ci = new GlideRecord("sn_vul_r7_rapid7_vulnerable_items_import");
new_ci.setValue("asset_id", "9999991");
new_ci.setValue("fqdn", "test1.example.com");
new_ci.setValue("name", "test1");
new_ci.setValue("ip_address", "1.1.1.1");
new_ci.setValue("mac_address", "");
new_ci.setValue("os_description", "Inserted by Rapid7CILookup test harness");
new_ci.setValue("os_family", "Linux");
new_ci.setValue("os_name", "Linux");
new_ci.setValue("os_vendor", "Linux");
new_ci.setValue("os_version", "2.6.18");
new_ci.setValue("discovery_source", "Rapid7");
new_ci.setValue("first_discovered", "2019-02-11 01:13:34.358");

var final_ci = sn_vul_r7.Rapid7CILookup.lookupCI(new_ci);

What am I doing wrong?

2 REPLIES 2

miked_jones
Giga Expert

It doesn't look like you are not actually initializing an instance of your class.

Try something like:

var final_ci = new Rapid7CILookup().lookupCI(new_ci);

That threw an error, but based on your hint this works:

var r7 = new Rapid7CILookup();
var final_ci = r7.lookupCI(new_ci);

 

Thanks...