github.com/newrelic/newrelic-client-go@v1.1.0/pkg/servicelevel/servicelevel_api.go (about) 1 // Code generated by tutone: DO NOT EDIT 2 package servicelevel 3 4 import ( 5 "context" 6 7 "github.com/newrelic/newrelic-client-go/pkg/common" 8 "github.com/newrelic/newrelic-client-go/pkg/errors" 9 ) 10 11 // Creates a new SLI. 12 func (a *Servicelevel) ServiceLevelCreate( 13 entityGUID common.EntityGUID, 14 indicator ServiceLevelIndicatorCreateInput, 15 ) (*ServiceLevelIndicator, error) { 16 return a.ServiceLevelCreateWithContext(context.Background(), 17 entityGUID, 18 indicator, 19 ) 20 } 21 22 // Creates a new SLI. 23 func (a *Servicelevel) ServiceLevelCreateWithContext( 24 ctx context.Context, 25 entityGUID common.EntityGUID, 26 indicator ServiceLevelIndicatorCreateInput, 27 ) (*ServiceLevelIndicator, error) { 28 29 resp := ServiceLevelCreateQueryResponse{} 30 vars := map[string]interface{}{ 31 "entityGuid": entityGUID, 32 "indicator": indicator, 33 } 34 35 if err := a.client.NerdGraphQueryWithContext(ctx, ServiceLevelCreateMutation, vars, &resp); err != nil { 36 return nil, err 37 } 38 39 return &resp.ServiceLevelIndicator, nil 40 } 41 42 type ServiceLevelCreateQueryResponse struct { 43 ServiceLevelIndicator ServiceLevelIndicator `json:"ServiceLevelCreate"` 44 } 45 46 const ServiceLevelCreateMutation = `mutation( 47 $entityGuid: EntityGuid!, 48 $indicator: ServiceLevelIndicatorCreateInput!, 49 ) { serviceLevelCreate( 50 entityGuid: $entityGuid, 51 indicator: $indicator, 52 ) { 53 createdAt 54 createdBy { 55 email 56 gravatar 57 id 58 name 59 } 60 description 61 entityGuid 62 events { 63 account { 64 id 65 name 66 } 67 badEvents { 68 from 69 select { 70 attribute 71 function 72 } 73 where 74 } 75 goodEvents { 76 from 77 select { 78 attribute 79 function 80 } 81 where 82 } 83 validEvents { 84 from 85 select { 86 attribute 87 function 88 } 89 where 90 } 91 } 92 guid 93 id 94 name 95 objectives { 96 description 97 name 98 target 99 timeWindow { 100 rolling { 101 count 102 unit 103 } 104 } 105 } 106 updatedAt 107 updatedBy { 108 email 109 gravatar 110 id 111 name 112 } 113 } }` 114 115 // Deletes an existing SLI by the GUID. 116 // iD optional field manually removed in favor of gUID to favor it's deprecation 117 func (a *Servicelevel) ServiceLevelDelete( 118 gUID common.EntityGUID, 119 ) (*ServiceLevelIndicator, error) { 120 return a.ServiceLevelDeleteWithContext(context.Background(), 121 gUID, 122 ) 123 } 124 125 // Deletes an existing SLI by the GUID. 126 // iD optional field manually removed in favor of gUID to favor it's deprecation 127 func (a *Servicelevel) ServiceLevelDeleteWithContext( 128 ctx context.Context, 129 gUID common.EntityGUID, 130 ) (*ServiceLevelIndicator, error) { 131 132 resp := ServiceLevelDeleteQueryResponse{} 133 vars := map[string]interface{}{ 134 "guid": gUID, 135 } 136 137 if err := a.client.NerdGraphQueryWithContext(ctx, ServiceLevelDeleteMutation, vars, &resp); err != nil { 138 return nil, err 139 } 140 141 return &resp.ServiceLevelIndicator, nil 142 } 143 144 type ServiceLevelDeleteQueryResponse struct { 145 ServiceLevelIndicator ServiceLevelIndicator `json:"ServiceLevelDelete"` 146 } 147 148 // id optional field manually removed in favor of guid to favor it's deprecation 149 const ServiceLevelDeleteMutation = `mutation( 150 $guid: EntityGuid, 151 ) { serviceLevelDelete( 152 guid: $guid, 153 ) { 154 createdAt 155 createdBy { 156 email 157 gravatar 158 id 159 name 160 } 161 description 162 entityGuid 163 events { 164 account { 165 id 166 name 167 } 168 badEvents { 169 from 170 select { 171 attribute 172 function 173 } 174 where 175 } 176 goodEvents { 177 from 178 select { 179 attribute 180 function 181 } 182 where 183 } 184 validEvents { 185 from 186 select { 187 attribute 188 function 189 } 190 where 191 } 192 } 193 guid 194 id 195 name 196 objectives { 197 description 198 name 199 target 200 timeWindow { 201 rolling { 202 count 203 unit 204 } 205 } 206 } 207 updatedAt 208 updatedBy { 209 email 210 gravatar 211 id 212 name 213 } 214 } }` 215 216 // Updates an existing SLI by the GUID. 217 // iD optional field manually removed in favor of gUID to favor it's deprecation 218 func (a *Servicelevel) ServiceLevelUpdate( 219 gUID common.EntityGUID, 220 indicator ServiceLevelIndicatorUpdateInput, 221 ) (*ServiceLevelIndicator, error) { 222 return a.ServiceLevelUpdateWithContext(context.Background(), 223 gUID, 224 indicator, 225 ) 226 } 227 228 // Updates an existing SLI by the GUID. 229 // iD optional field manually removed in favor of gUID to favor it's deprecation 230 func (a *Servicelevel) ServiceLevelUpdateWithContext( 231 ctx context.Context, 232 gUID common.EntityGUID, 233 indicator ServiceLevelIndicatorUpdateInput, 234 ) (*ServiceLevelIndicator, error) { 235 236 resp := ServiceLevelUpdateQueryResponse{} 237 vars := map[string]interface{}{ 238 "guid": gUID, 239 "indicator": indicator, 240 } 241 242 if err := a.client.NerdGraphQueryWithContext(ctx, ServiceLevelUpdateMutation, vars, &resp); err != nil { 243 return nil, err 244 } 245 246 return &resp.ServiceLevelIndicator, nil 247 } 248 249 type ServiceLevelUpdateQueryResponse struct { 250 ServiceLevelIndicator ServiceLevelIndicator `json:"ServiceLevelUpdate"` 251 } 252 253 // id optional field manually removed in favor of guid to favor it's deprecation 254 const ServiceLevelUpdateMutation = `mutation( 255 $guid: EntityGuid, 256 $indicator: ServiceLevelIndicatorUpdateInput!, 257 ) { serviceLevelUpdate( 258 guid: $guid, 259 indicator: $indicator, 260 ) { 261 createdAt 262 createdBy { 263 email 264 gravatar 265 id 266 name 267 } 268 description 269 entityGuid 270 events { 271 account { 272 id 273 name 274 } 275 badEvents { 276 from 277 select { 278 attribute 279 function 280 } 281 where 282 } 283 goodEvents { 284 from 285 select { 286 attribute 287 function 288 } 289 where 290 } 291 validEvents { 292 from 293 select { 294 attribute 295 function 296 } 297 where 298 } 299 } 300 guid 301 id 302 name 303 objectives { 304 description 305 name 306 target 307 timeWindow { 308 rolling { 309 count 310 unit 311 } 312 } 313 } 314 updatedAt 315 updatedBy { 316 email 317 gravatar 318 id 319 name 320 } 321 } }` 322 323 // The SLIs attached to the entity. 324 func (a *Servicelevel) GetIndicators( 325 entityGUID common.EntityGUID, 326 ) (*[]ServiceLevelIndicator, error) { 327 return a.GetIndicatorsWithContext(context.Background(), 328 entityGUID, 329 ) 330 } 331 332 // The SLIs attached to the entity. 333 func (a *Servicelevel) GetIndicatorsWithContext( 334 ctx context.Context, 335 entityGUID common.EntityGUID, 336 ) (*[]ServiceLevelIndicator, error) { 337 338 resp := indicatorsResponse{} 339 vars := map[string]interface{}{ 340 "entityGUID": entityGUID, 341 } 342 343 if err := a.client.NerdGraphQueryWithContext(ctx, getIndicatorsQuery, vars, &resp); err != nil { 344 return nil, err 345 } 346 347 if len(resp.Actor.Entity.ServiceLevel.Indicators) == 0 { 348 return nil, errors.NewNotFound("") 349 } 350 351 return &resp.Actor.Entity.ServiceLevel.Indicators, nil 352 } 353 354 const getIndicatorsQuery = `query( 355 $entityGUID: EntityGuid!, 356 ) { actor { entity(guid: $entityGUID) { serviceLevel { indicators { 357 createdAt 358 createdBy { 359 email 360 gravatar 361 id 362 name 363 } 364 description 365 entityGuid 366 events { 367 account { 368 id 369 name 370 } 371 badEvents { 372 from 373 select { 374 attribute 375 function 376 } 377 where 378 } 379 goodEvents { 380 from 381 select { 382 attribute 383 function 384 } 385 where 386 } 387 validEvents { 388 from 389 select { 390 attribute 391 function 392 } 393 where 394 } 395 } 396 guid 397 id 398 name 399 objectives { 400 description 401 name 402 target 403 timeWindow { 404 rolling { 405 count 406 unit 407 } 408 } 409 } 410 updatedAt 411 updatedBy { 412 email 413 gravatar 414 id 415 name 416 } 417 } } } } }`