-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipeline-processing-monitor.yml
160 lines (148 loc) · 6.52 KB
/
azure-pipeline-processing-monitor.yml
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
name: $(Major).$(Minor).$(Patch)
variables:
Major: 1
Minor: 0
Patch: $[counter(format('{0}.{1}', variables['Major'], variables['Minor']), 0)]
processMonitorServiceAccount: gzw-admin
processMonitorTaskName: Processing Monitor
CLIENT: CLIENT
ENVIRONMENT: Local
LOG_FILE_PATH: C:\dev\git\env\Local\report\logs\GZW.log
WAIT_TIME: 60
SEND_EMAIL: Yes
ENABLE_LOGGING: Y
EMAIL_FROM_ADDRESS: [email protected]
EMAIL_TO_ADDRESS: [email protected]
SMTP_SERVER: smtp.office365.com
SMTP_PORT: 587
SMTP_USER: [email protected]
OVERNIGHT_START_TIME: 18:00
OVERNIGHT_FINISH_TIME: 05:00
LOG_DIFF_TIME_THRESHOLD: 5
GRAFANA_BASE_URL: http://192.168.17.95/grafana
resources:
- repo: self
trigger:
branches:
include:
- master
paths:
include:
- Processing_Monitor/*
- azure-pipeline-processing-monitor.yml
stages:
- stage: Build
displayName: Build
jobs:
- job: Build
displayName: Build Processing Monitor Solution
pool:
name: LocalTest
workspace:
clean: all
steps:
- powershell: |
New-Item -Path "$(Build.ArtifactStagingDirectory)\" -Name "ProcessMonitor" -ItemType Directory
Copy-Item $(Build.SourcesDirectory)\Processing_Monitor\* $(Build.ArtifactStagingDirectory)\ProcessMonitor\ -Recurse
displayName: 'Copy ProcessMonitor to Artifacts Directory'
- task: PublishPipelineArtifact@1
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)\ProcessMonitor\'
artifact: ProcessMonitorPackage
- stage: Deploy
dependsOn: Build
jobs:
- deployment: Deploy
displayName: Deploy ProcessMonitor Job
pool:
name: LocalTest
environment: Live
strategy:
runOnce:
deploy:
steps:
- powershell: |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$tags = @("deploy", "dev", "processmonitor", "started")
$body = @{
"what" = "Process Monitor - Deploy"
"tags" = $tags
"data" = "Started - Deploy of master branch"
} | ConvertTo-Json
$Header = @{"Authorization" = "$(GRAFANA_BEARER_TOKEN)"
"Accept" = "application/json"
"Content-Type" = "application/json"
}
Invoke-RestMethod -Method POST -Header $Header -Uri "$(GRAFANA_BASE_URL)/api/annotations/graphite" -Body $body
displayName: 'Post Grafana Annotation of Start Deploy'
env:
GRAFANA_BASE_URL: $(GRAFANA_BASE_URL) # Maps the secret variable $(token)
GRAFANA_BEARER_TOKEN: $(GRAFANA_BEARER_TOKEN)
- task: replacetokens@3
displayName: 'Replace secret tokens in **/*.properties file'
inputs:
rootDirectory: $(Pipeline.Workspace)\ProcessMonitorPackage\
targetFiles: '**/*.properties'
env:
ENVIRONMENT: $(ENVIRONMENT) # Maps the secret variable $(token)
LOG_FILE_PATH: $(LOG_FILE_PATH)
WAIT_TIME: $(WAIT_TIME)
SEND_EMAIL: $(SEND_EMAIL)
ENABLE_LOGGING: $(ENABLE_LOGGING)
EMAIL_FROM_ADDRESS: $(EMAIL_FROM_ADDRESS)
EMAIL_TO_ADDRESS: $(EMAIL_TO_ADDRESS)
SMTP_SERVER: $(SMTP_SERVER)
SMTP_PORT: $(SMTP_PORT)
SMTP_USER: $(SMTP_USER)
OVERNIGHT_START_TIME: $(OVERNIGHT_START_TIME)
OVERNIGHT_FINISH_TIME: $(OVERNIGHT_FINISH_TIME)
LOG_DIFF_TIME_THRESHOLD: $(LOG_DIFF_TIME_THRESHOLD)
API_KEY: $(API_KEY)
GECKO_PUSH_URL1: $(GECKO_PUSH_URL1)
CLIENT: $(CLIENT)
SMTP_PASSWORD: $(SMTP_PASSWORD)
- powershell: |
$ProgDir = Get-Item "C:\Program Files\telegraf"
$MaintDir = Get-Item "C:\DBOps"
if ($null -eq $ProgDir) {New-Item -Path "C:\Program Files\telegraf" -ItemType Directory -Force}
if ($null -eq $MaintDir){New-Item -Path "C:\DBOps" -ItemType Directory -Force}
displayName: 'Create Folder Structure'
- powershell: Copy-Item $(Pipeline.Workspace)\ProcessMonitorPackage\* c:\DBops -Recurse -Force
displayName: 'Copy files to directory'
- powershell: |
$TaskExists = Get-ScheduledTask -TaskName "$(processMonitorTaskName)" -ErrorAction SilentlyContinue | out-null
if ($null -eq $TaskExists){
$A = New-ScheduledTaskAction -Execute "Powershell.exe" -Argument '-NoProfile -NoLogo -NonInteractive -ExecutionPolicy Bypass -File C:\DBOps\processingMonitoring.ps1'
$T = New-ScheduledTaskTrigger -AtLogon
$P = New-ScheduledTaskPrincipal -UserID "NT AUTHORITY\SYSTEM" -RunLevel Highest
$S = New-ScheduledTaskSettingsSet
$D = New-ScheduledTask -Action $A -Principal $P -Trigger $T -Settings $S
Register-ScheduledTask -TaskPath "$(CLIENT)" -InputObject $D -TaskName "$(processMonitorTaskName)"
}
displayName: 'Create Scheduled Task if required'
env:
processMonitorTaskName: $(processMonitorTaskName) # Maps the secret variable $(token)
- powershell: |
Get-ScheduledTask -TaskName "$(processMonitorTaskName)" | Disable-ScheduledTask
Get-ScheduledTask -TaskName "$(processMonitorTaskName)" | Enable-ScheduledTask
Get-ScheduledTask -TaskName "$(processMonitorTaskName)" | Start-ScheduledTask
displayName: 'Restart Scheduled Task'
env:
processMonitorTaskName: $(processMonitorTaskName) # Maps the secret variable $(token)
- powershell: |
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$tags = @("deploy", "dev", "processmonitor", "finished")
$body = @{
"what" = "Process Monitor - Deploy"
"tags" = $tags
"data" = "Finished - Deploy of master branch"
} | ConvertTo-Json
$Header = @{"Authorization" = "$(GRAFANA_BEARER_TOKEN)"
"Accept" = "application/json"
"Content-Type" = "application/json"
}
Invoke-RestMethod -Method POST -Header $Header -Uri "$(GRAFANA_BASE_URL)/api/annotations/graphite" -Body $body
displayName: 'Post Grafana Annotation of Finished Deploy'
env:
GRAFANA_BASE_URL: $(GRAFANA_BASE_URL) # Maps the secret variable $(token)
GRAFANA_BEARER_TOKEN: $(GRAFANA_BEARER_TOKEN)