Class: Nexpose::ScheduledMaintenance

Inherits:
APIObject
  • Object
show all
Includes:
JsonSerializer
Defined in:
lib/nexpose/scheduled_maintenance.rb

Overview

Configuration structure for scheduled maintenance.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from JsonSerializer

#deserialize, #serialize, #to_hash

Methods inherited from APIObject

#object_from_hash

Constructor Details

#initialize(start:, enabled: true, type:, interval:, reindex: false, compress: true, cleanup: true, pause_local_scans: true, cancellation_window: 0) ⇒ ScheduledMaintenance

Returns a new instance of ScheduledMaintenance.



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/nexpose/scheduled_maintenance.rb', line 26

def initialize(start:, enabled: true, type:, interval:, reindex: false, compress: true, cleanup: true, pause_local_scans: true, cancellation_window: 0)
  @schedule_start      = start
  @enabled             = enabled
  @schedule_type       = type
  @schedule_interval   = interval.to_i
  @reindex             = reindex
  @compress            = compress
  @cleanup             = cleanup
  @pause_local_scans   = pause_local_scans
  @cancellation_window = cancellation_window.to_i
end

Instance Attribute Details

#cancellation_windowObject

Number of minutes to wait for running scans to pause/complete before aborting the maintenance task. Defaults to 0 if not set



24
25
26
# File 'lib/nexpose/scheduled_maintenance.rb', line 24

def cancellation_window
  @cancellation_window
end

#cleanupObject

Whether the cleanup task should run. Defaults to true if not set



20
21
22
# File 'lib/nexpose/scheduled_maintenance.rb', line 20

def cleanup
  @cleanup
end

#compressObject

Whether the compression task should run. Defaults to true if not set



18
19
20
# File 'lib/nexpose/scheduled_maintenance.rb', line 18

def compress
  @compress
end

#enabledObject

Whether or not this maintenance schedule is enabled. Defaults to true if not set



8
9
10
# File 'lib/nexpose/scheduled_maintenance.rb', line 8

def enabled
  @enabled
end

#pause_local_scansObject

Whether the maintenance should pause all local scans or wait for local scans to complete. Defaults to true if not set



22
23
24
# File 'lib/nexpose/scheduled_maintenance.rb', line 22

def pause_local_scans
  @pause_local_scans
end

#reindexObject

Whether the reindex task should run. Defaults to true if not set



16
17
18
# File 'lib/nexpose/scheduled_maintenance.rb', line 16

def reindex
  @reindex
end

#schedule_intervalObject

The repeat interval based upon type.



12
13
14
# File 'lib/nexpose/scheduled_maintenance.rb', line 12

def schedule_interval
  @schedule_interval
end

#schedule_startObject

Starting time of the maintenance task (in unix epoch with milliseconds. Example: 1464956590000)



14
15
16
# File 'lib/nexpose/scheduled_maintenance.rb', line 14

def schedule_start
  @schedule_start
end

#schedule_typeObject

Valid schedule types: daily, hourly, monthly-date, monthly-day, weekly.



10
11
12
# File 'lib/nexpose/scheduled_maintenance.rb', line 10

def schedule_type
  @schedule_type
end

Class Method Details

.delete(nsc) ⇒ Object



86
87
88
# File 'lib/nexpose/scheduled_maintenance.rb', line 86

def self.delete(nsc)
  AJAX.delete(nsc, '/api/2.1/schedule_maintenance/', AJAX::CONTENT_TYPE::JSON)
end

.from_hash(hash) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/nexpose/scheduled_maintenance.rb', line 47

def self.from_hash(hash)
  repeat_backup_hash = hash[:repeat_type]
  backup = new(start: hash[:start_date],
               enabled: hash[:enabled],
               type: repeat_backup_hash[:type],
               interval: repeat_backup_hash[:interval],
               reindex: hash[:reindex],
               compress: hash[:compression],
               cleanup: hash[:cleanup],
               pause_local_scans: hash[:pause_local_scans],
               cancellation_window: hash[:cancellation_window])
  backup
end

.load(nsc) ⇒ Object



79
80
81
82
83
84
# File 'lib/nexpose/scheduled_maintenance.rb', line 79

def self.load(nsc)
  uri  = '/api/2.1/schedule_maintenance/'
  resp = AJAX.get(nsc, uri, AJAX::CONTENT_TYPE::JSON)
  hash = JSON.parse(resp, symbolize_names: true).first
  Nexpose::ScheduledMaintenance.from_hash(hash || [])
end

Instance Method Details

#save(nsc) ⇒ Object



42
43
44
45
# File 'lib/nexpose/scheduled_maintenance.rb', line 42

def save(nsc)
  params = to_json
  AJAX.post(nsc, '/api/2.1/schedule_maintenance/', params, AJAX::CONTENT_TYPE::JSON)
end

#to_hObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/nexpose/scheduled_maintenance.rb', line 61

def to_h
  maintenance_hash = {
    start_date: @schedule_start,
    enabled: @enabled,
    cleanup: @cleanup,
    reindex: @reindex,
    compression: @compress,
    pause_local_scans: @pause_local_scans,
    cancellation_window: @cancellation_window
  }
  repeat_hash = {
    type: @schedule_type,
    interval: @schedule_interval
  }
  maintenance_hash[:repeat_type] = repeat_hash
  maintenance_hash
end

#to_jsonObject



38
39
40
# File 'lib/nexpose/scheduled_maintenance.rb', line 38

def to_json
  JSON.generate(to_h)
end