-
Notifications
You must be signed in to change notification settings - Fork 0
/
SCAPRemediate.rb
58 lines (46 loc) · 1.84 KB
/
SCAPRemediate.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Author: Lucy Kerner([email protected])
$evm.log("info", "SCAP Remediate Start")
require 'rubygems'
require 'net/ssh'
require 'rest_client'
require "xmlrpc/client"
#We can only work with a VM that's powered on
vm = $evm.root['vm']
if vm.power_state == "off"
$evm.log("info", "SCAP - VM not powered on")
exit MIQ_ABORT
end
#Definitions for the Satellite
@SATELLITE_URL = "http://" + $evm.object['satellite_ip'] + "/rpc/api"
@SATELLITE_LOGIN = $evm.object['satellite_user']
@SATELLITE_PASSWORD = $evm.object.decrypt('satellite_password')
#Get the chosen SCAP profile
#profile = $evm.root['dialog_SCAP_Profiles']
profile = $evm.root['dialog_SCAPProfiles']
@PROFILE = "--profile " + "#{profile}"
$evm.log("info", "SCAP - Profile: #{@PROFILE}")
if @PROFILE == "--profile "
$evm.log("info", "SCAP - Exit, no profile")
exit MIQ_OK
end
#Definitions for the client; it would be better if I could get the domain name
theserver = "#{vm.name}"
$evm.log("info", "SCAP - Server: #{theserver}")
#USER = 'cf3operator'
USER = $evm.object['vm_user']
PASS = $evm.object.decrypt('vm_password')
#Get the IP address of the client
vm.ipaddresses.each do |vm_ipaddress|
$evm.log("info", "SCAP - IP address: #{vm_ipaddress}")
HOSTIP = vm_ipaddress
end
$evm.log("info", "Before logging into satellite...")
#Get the xccdf file that the chosen profile is in
Net::SSH.start( HOSTIP, USER, :password => PASS, :paranoid=> false ) do|ssh|
ospcommand="oscap xccdf eval #{@PROFILE} --results /dev/null --remediate --cpe /usr/share/xml/scap/ssg/content/ssg-rhel6-cpe-dictionary.xml /usr/share/xml/scap/ssg/content/ssg-rhel6-xccdf.xml"
$evm.log("info", "SCAP - Remediation Command ospcommand is: #{ospcommand}")
REMEDIATIONOUT = ssh.exec!(ospcommand)
$evm.log("info", "SCAP - Remediation Command STDOUT is: #{REMEDIATIONOUT}")
end
$evm.log("info", "SCAPRemediate Method Ended")
exit MIQ_OK