Class: Nexpose::Connection

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

Instance Method Summary (collapse)

Instance Method Details

- (Asset) getAsset(host)

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.



111
112
113
# File 'lib\nexpose-functions.rb', line 111

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

- (Hash) getScanTemplatesbyId

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.



88
89
90
91
92
93
94
# File 'lib\nexpose-functions.rb', line 88

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

- (Hash) getScanTemplatesbyName

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.



99
100
101
102
103
104
105
# File 'lib\nexpose-functions.rb', line 99

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

- (Hash) getSitesInfobyId

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.



66
67
68
69
70
71
72
# File 'lib\nexpose-functions.rb', line 66

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

- (Hash) getSitesInfobyName

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.



77
78
79
80
81
82
83
# File 'lib\nexpose-functions.rb', line 77

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

- (Array[Asset]) notScannedSince(days)

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.



119
120
121
# File 'lib\nexpose-functions.rb', line 119

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

- (String) siteid_to_name(siteid)

Get the name for a site ID.

Parameters:

  • siteid (Fixnum)

    a site id to look up.

Returns:

  • (String)

    the name of the site.



55
56
57
58
59
60
61
# File 'lib\nexpose-functions.rb', line 55

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

- (Fixnum) sitename_to_id(sitename)

Get the ID for a site name.

Parameters:

  • sitename (String)

    the site name to look up.

Returns:

  • (Fixnum)

    the id for the site name.



43
44
45
46
47
48
49
# File 'lib\nexpose-functions.rb', line 43

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

- (Boolean) validate_engineid(engID)

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.



29
30
31
32
33
34
35
36
37
# File 'lib\nexpose-functions.rb', line 29

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