/
Write-VdcLog.ps1
197 lines (145 loc) · 5.49 KB
/
Write-VdcLog.ps1
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
function Write-VdcLog {
<#
.SYNOPSIS
Write entries to the TLSPDC log
.DESCRIPTION
Write entries to the log for custom event groups.
It is not permitted to write to the default log.
Ensure the group and event id are correct as the api will not fail if incorrect.
.PARAMETER CustomEventGroup
ID containing hex values between 0100-0299 referring to the created custom group.
.PARAMETER EventId
Event ID from within the EventGroup provided, a 4 character hex value.
Only provide the 4 character event id, do not precede with group ID.
.PARAMETER Component
Path to the item this event is associated with
.PARAMETER Severity
Severity of the event
.PARAMETER SourceIp
The IP that originated the event
.PARAMETER ComponentID
Component ID that originated the event
.PARAMETER ComponentSubsystem
Component subsystem that originated the event
.PARAMETER Text1
String data to write to log. See link for event ID messages for more info.
.PARAMETER Text2
String data to write to log. See link for event ID messages for more info.
.PARAMETER Value1
Integer data to write to log. See link for event ID messages for more info.
.PARAMETER Value2
Integer data to write to log. See link for event ID messages for more info.
.PARAMETER VenafiSession
Authentication for the function.
The value defaults to the script session object $VenafiSession created by New-VenafiSession.
A TLSPDC token can also be provided.
If providing a TLSPDC token, an environment variable named VDC_SERVER must also be set.
.INPUTS
none
.OUTPUTS
none
.EXAMPLE
Write-VdcLog -CustomEventGroup '0200' -EventId '0001' -Component '\ved\policy\mycert.com'
Log an event to a custom group
.LINK
http://VenafiPS.readthedocs.io/en/latest/functions/Write-VdcLog/
.LINK
https://github.com/Venafi/VenafiPS/blob/main/VenafiPS/Public/Write-VdcLog.ps1
.LINK
https://docs.venafi.com/Docs/current/TopNav/Content/SDK/WebSDK/r-SDK-POST-Log.php
#>
[CmdletBinding(SupportsShouldProcess, DefaultParameterSetName = 'DefaultGroup')]
[Alias('Write-TppLog')]
param (
[Parameter(Mandatory, ParameterSetName = 'DefaultGroup')]
[string] $EventGroup,
[Parameter(Mandatory, ParameterSetName = 'CustomGroup')]
[ValidateScript({
if ( $_ -match '^0[1-2]\d\d$' ) {
$true
} else {
throw "$_ is an invalid group. Custom event groups must be betwen 0100-0299."
}
})]
[string] $CustomEventGroup,
[Parameter(Mandatory)]
[ValidateScript({
if ( $_ -match '^[0-9a-fA-F]{4}$' ) {
$true
} else {
throw "$_ is an invalid event ID. Event IDs must be a 4 character hex value."
}
})]
[string] $EventId,
[Parameter(Mandatory)]
[ValidateNotNullOrEmpty()]
[String] $Component,
[Parameter()]
[TppEventSeverity] $Severity,
[Parameter()]
[ipaddress] $SourceIp,
[Parameter()]
[int] $ComponentID,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $ComponentSubsystem,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $Text1,
[Parameter()]
[ValidateNotNullOrEmpty()]
[string] $Text2,
[Parameter()]
[int] $Value1,
[Parameter()]
[int] $Value2,
[Parameter()]
[psobject] $VenafiSession
)
if ( $PSCmdlet.ParameterSetName -eq 'DefaultGroup' ) {
throw 'Writing to built-in event groups is no longer supported by Venafi. You can write to custom event groups. -EventGroup will be deprecated in a future release.'
}
Test-VenafiSession -VenafiSession $VenafiSession -Platform 'VDC'
# the event id is the group id coupled with the event id
$fullEventId = "$CustomEventGroup$EventId"
# convert the hex based eventid to decimal equivalent
$decEventId = [System.Convert]::ToInt64($fullEventId, 16)
$params = @{
Method = 'Post'
UriLeaf = 'Log/'
Body = @{
ID = $decEventId
Component = $Component
}
}
if ( $PSBoundParameters.ContainsKey('Severity') ) {
$params.Body.Add('Severity', [TppEventSeverity]::$Severity)
}
if ( $PSBoundParameters.ContainsKey('SourceIp') ) {
$params.Body.Add('SourceIp', $SourceIp.ToString())
}
if ( $PSBoundParameters.ContainsKey('ComponentID') ) {
$params.Body.Add('ComponentID', $ComponentID)
}
if ( $PSBoundParameters.ContainsKey('ComponentSubsystem') ) {
$params.Body.Add('ComponentSubsystem', $ComponentSubsystem)
}
if ( $PSBoundParameters.ContainsKey('Text1') ) {
$params.Body.Add('Text1', $Text1)
}
if ( $PSBoundParameters.ContainsKey('Text2') ) {
$params.Body.Add('Text2', $Text2)
}
if ( $PSBoundParameters.ContainsKey('Value1') ) {
$params.Body.Add('Value1', $Value1)
}
if ( $PSBoundParameters.ContainsKey('Value2') ) {
$params.Body.Add('Value2', $Value2)
}
if ( $PSCmdlet.ShouldProcess($Component, 'Write log entry') ) {
$response = Invoke-VenafiRestMethod @params
if ( $response.LogResult -eq 1 ) {
throw "Writing to the TLSPDC log failed. Ensure you have View permission and Read permission to the default SQL channel object."
}
}
}