-
Notifications
You must be signed in to change notification settings - Fork 9
/
qualys-deploy-ssm.txt
198 lines (198 loc) · 7.41 KB
/
qualys-deploy-ssm.txt
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
{
"schemaVersion": "2.2",
"description": "Manage Qualys Cloud Agent on EC2 instances",
"parameters": {
"ActivationID": {
"type": "String",
"description": "(Required) Enter ActivationID obtained from Qualys CP "
},
"CustomerID": {
"type": "String",
"description": "(Required) Enter CustomerID as displayed in your account"
},
"AgentLocationWindows": {
"type": "String",
"default": "",
"description": "(Optional) Enter FQDN or full path of Windows Qualys Cloud Agent Installer's location"
},
"AgentLocationDebian": {
"type": "String",
"default": "",
"description": "(Optional) Enter FQDN or full path of Debian Qualys Cloud Agent Installer's location"
},
"AgentLocationRPM": {
"type": "String",
"default": "",
"description": "(Optional) Enter FQDN or full path of RPM Qualys Cloud Agent Installer's location"
},
"LogLevel": {
"type": "String",
"default": "0",
"description": "(Optional) A higher value corresponds to more verbosity. Default is to report only errors (0) ",
"allowedValues": [
"0",
"1",
"2",
"3",
"4",
"5"
]
}
},
"mainSteps": [
{
"precondition": {
"StringEquals": [
"platformType",
"Linux"
]
},
"action": "aws:runShellScript",
"name": "InstallQualysCloudAgentOnLinux",
"inputs": {
"id": "0.aws:runShellScript",
"timeoutSeconds": 600,
"runCommand": [
"#!/bin/bash",
"#set -eux",
"#Check Whether the Qualys Cloud Agent is already installed",
"status=$( sudo service qualys-cloud-agent status | grep Active )",
"if [[ -z \"$status\" ]];",
"then",
" # Check whether curl or wget is present in the system",
" if hash curl 2>/dev/null",
" then",
" DOWNLOAD_CMD=\"curl -s --fail --retry 5 --max-time 30\"",
" CONSOLE_ARG=\"\"",
" TO_FILE_ARG=\" -o \"",
" HEADER_ARG=\" --head \"",
" else",
" DOWNLOAD_CMD=\"wget --quiet --tries=5 --timeout=30 \"",
" CONSOLE_ARG=\" -qO- \"",
" TO_FILE_ARG=\" -O \"",
" HEADER_ARG=\" -S --spider \"",
" fi",
" # Check whether the OS is Debian or RPM based Linux and set the download location",
" os=$( grep -Ei 'debian|buntu|mint' /etc/*release )",
" if [[ -n \"$os\" || -f \"/etc/debian_version\" ]];",
" then",
" INSTALLER_FILE_URL={{ AgentLocationDebian }}",
" opersys=\"DEB\"",
" else",
" INSTALLER_FILE_URL={{ AgentLocationRPM }}",
" opersys=\"RPM\"",
" fi",
" Downloadfile()",
" {",
" ${DOWNLOAD_CMD} ${TO_FILE_ARG} qualys-cloud-agent.x86_64 ${INSTALLER_FILE_URL}",
" if [[ $? != 0 ]];",
" then",
" echo \"Failed to download installer from ${INSTALLER_FILE_URL}\"",
" exit 3",
" fi",
" }",
" # Checks whether agent location is a FQDN or full path and invoke download or copy function ",
" if [[ -n \"$INSTALLER_FILE_URL\" ]]; ",
" then",
" if [[ \"${INSTALLER_FILE_URL:0:4}\" == 'http' ]] ; ",
" then",
" Downloadfile",
" else",
" cp $INSTALLER_FILE_URL qualys-cloud-agent.x86_64 ",
" fi",
" else",
" echo \"No installation path specified for Qualys Cloud Agent\"",
" exit 4",
" fi",
" if [ \"$opersys\" = \"RPM\" ];",
" then",
" sleep 5",
" sudo rpm -ivh qualys-cloud-agent.x86_64",
" sleep 5",
" sudo /usr/local/qualys/cloud-agent/bin/qualys-cloud-agent.sh LogLevel={{ LogLevel }} ActivationId={{ ActivationID }} CustomerId={{ CustomerID }}",
" else",
" sudo dpkg --install qualys-cloud-agent.x86_64",
" sleep 5",
" sudo /usr/local/qualys/cloud-agent/bin/qualys-cloud-agent.sh LogLevel={{ LogLevel }} ActivationId={{ ActivationID }} CustomerId={{ CustomerID }}",
" fi",
"else",
"echo \"QualysCloudAgent is already installed on this and running\"",
"fi"
]
}
},
{
"precondition": {
"StringEquals": [
"platformType",
"Windows"
]
},
"action": "aws:runPowerShellScript",
"name": "InstallQualysCloudAgentOnWindows",
"inputs": {
"id": "0.aws:runPowerShellScript",
"timeoutSeconds": 600,
"runCommand": [
"function New-TemporaryDirectory {",
" $parent = [System.IO.Path]::GetTempPath()",
" [string] $name = [System.Guid]::NewGuid()",
" New-Item -ItemType Directory -Path (Join-Path $parent $name)",
"}",
"$tempdir = New-TemporaryDirectory",
"Set-Location -Path $tempdir",
"$agentInstaller=\"QualysCloudAgent.exe\"",
"$agentInstallerlog=Join-Path $tempdir $agentInstaller",
"if (Get-Service \"QualysAgent\" -ErrorAction SilentlyContinue)",
"{",
" Write-Host \"Qualys Cloud Agent is already installed, Exiting\"",
" exit 0",
"}",
"#Download the Qualys Cloud agent",
"Function Download_file",
"{",
" Try",
" {",
" Invoke-WebRequest $installerUrl -OutFile $agentInstallerlog",
" }",
" Catch",
" {",
" Write-Host \"Error while downloading installer\"",
" Write-Host $_.Exception|format-list -force",
" exit 3",
" }",
"}",
"#Check whether agent location is a FQDN or full path and invoke download or copy function",
"if ('{{ AgentLocationWindows }}' -ne '')",
"{",
" $installerUrl = '{{ AgentLocationWindows }}'",
" if ( $installerUrl.Substring(0,4) -eq 'http')",
" {",
" Download_file",
" }",
" Else",
" {",
" Copy-Item $agentInstallerlog ",
" }",
"}",
"Else ",
"{",
" Write-Host \"No installation path specified for Qualys Cloud Agent\"",
" exit 5",
"}",
"# Install the Qualys Cloud Agent",
"Try",
"{",
" & $agentInstallerlog CustomerId={{ CustomerID }} ActivationId={{ ActivationID }}",
"}",
"Catch",
"{",
" Write-Host \"Installation failed, exception raised during installation\"",
" Write-Host $_.Exception|format-list -force",
" exit 6",
"}"
]
}
}
]
}