Class: Nexpose::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/nexpose-functions.rb

Instance Method Summary collapse

Instance Method Details

#getAsset(host) ⇒ Asset

Get an Asset object for the specified host IP.

Parameters:

  • host (String)

    the hostname to get an Asset object for.

Returns:

  • (Asset)

    the Asset object for the host.



114
115
116
# File 'lib/nexpose-functions.rb', line 114

def getAsset(host)
    return self.filter(Nexpose::Search::Field::ASSET, Nexpose::Search::Operator::IS, host)
end

#getScanTemplatesbyIdHash

Get a Hash object containing pairs of scan template names/ids where the Hash key is the scan template id.

Returns:

  • (Hash)

    object with scan template ids as the keys and scan template names as the values.



91
92
93
94
95
96
97
# File 'lib/nexpose-functions.rb', line 91

def getScanTemplatesbyId()
    templateinfo = {}
    self.list_scan_templates.each { |template|
        templateinfo[template.id] = template.name
    }
    return templateinfo
end

#getScanTemplatesbyNameHash

Get a Hash object containing pairs of scan template names/ids where the Hash key is the scan template name.

Returns:

  • (Hash)

    object with scan template names as the keys and scan template ids as the values.



102
103
104
105
106
107
108
# File 'lib/nexpose-functions.rb', line 102

def getScanTemplatesbyName()
    templateinfo = {}
    self.list_scan_templates.each { |template|
        templateinfo[template.name] = template.id
    }
    return templateinfo
end

#getSitesInfobyIdHash

Get a Hash object containing pairs of site ids/names where the Hash key is the site id.

Returns:

  • (Hash)

    object with site ids as the keys and site names as the values.



69
70
71
72
73
74
75
# File 'lib/nexpose-functions.rb', line 69

def getSitesInfobyId()
    sitesinfo = {}
    self.list_sites.each { |site|
        sitesinfo[site.id] = site.name
    }
    return sitesinfo
end

#getSitesInfobyNameHash

Get a Hash object containing pairs of site names/ids where the Hash key is the site name.

Returns:

  • (Hash)

    object with site names as the keys and site ids as the values.



80
81
82
83
84
85
86
# File 'lib/nexpose-functions.rb', line 80

def getSitesInfobyName()
    sitesinfo = {}
    self.list_sites.each { |site|
        sitesinfo[site.name] = site.id
    }
    return sitesinfo
end

#notScannedSince(days) ⇒ Array[Asset]

Get an array of Asset objects for hosts that have not been scanned in ‘X’ days.

Parameters:

  • days (Fixnum)

    the number of days back to check for unscanned hosts.

Returns:

  • (Array[Asset])

    array of Asset objects for the hosts.



122
123
124
# File 'lib/nexpose-functions.rb', line 122

def notScannedSince(days)
    return self.filter(Nexpose::Search::Field::SCAN_DATE, Nexpose::Search::Operator::EARLIER_THAN, days.to_i)
end

#siteid_to_name(siteid) ⇒ String

Get the name for a site ID.

Parameters:

  • siteid (Fixnum)

    a site id to look up.

Returns:

  • (String)

    the name of the site.



58
59
60
61
62
63
64
# File 'lib/nexpose-functions.rb', line 58

def siteid_to_name(siteid)
    self.list_sites.each { |site|
        if site.id == siteid
            return site.name
        end
    }
end

#sitename_to_id(sitename) ⇒ Fixnum

Get the ID for a site name.

Parameters:

  • sitename (String)

    the site name to look up.

Returns:

  • (Fixnum)

    the id for the site name.



46
47
48
49
50
51
52
# File 'lib/nexpose-functions.rb', line 46

def sitename_to_id(sitename)
    self.list_sites.each { |site|
        if site.name == sitename
            return site.id
        end
    }
end

#validate_engineid(engID) ⇒ Boolean

Check if an input is a valid engine id.

Parameters:

  • engID (Fixnum)

    an id to check against the list of valid engine ids.

Returns:

  • (Boolean)

    true if engID is valid.



32
33
34
35
36
37
38
39
40
# File 'lib/nexpose-functions.rb', line 32

def validate_engineid(engID)
    # Create array of engine ids for validation
    engine_ids = []
    for eng in self.list_engines do
        engine_ids << eng.id
    end

    return engine_ids.include?(engID.to_i)    
end