Skip to content

Conversation

@vishrutshah
Copy link
Owner

Usage

Example 1:

(env) vishrut@usermac azure-cli (implement-activity-logs-filter) $ az monitor activity-logs list --select authorization status --resource-uri /subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourceGroups/vishrutrg/providers/Microsoft.Web/sites/vishrutwebapp --max-events 1
[
  {
    "authorization": {
      "action": "Microsoft.Web/sites/stop/action",
      "role": null,
      "scope": "/subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourcegroups/vishrutrg/providers/Microsoft.Web/sites/vishrutwebapp"
    },
    "caller": null,
    "category": null,
    "claims": null,
    "correlationId": null,
    "description": null,
    "eventDataId": null,
    "eventName": null,
    "eventTimestamp": null,
    "httpRequest": null,
    "id": "/subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourcegroups/vishrutrg/providers/Microsoft.Web/sites/vishrutwebapp/events/7b48365e-8644-48d5-9f5f-2f098f1aa040/ticks/636216018978897909",
    "level": null,
    "operationId": null,
    "operationName": null,
    "properties": null,
    "resourceGroupName": null,
    "resourceId": "/subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourcegroups/vishrutrg/providers/Microsoft.Web/sites/vishrutwebapp",
    "resourceProviderName": null,
    "resourceType": null,
    "status": {
      "localizedValue": "Succeeded",
      "value": "Succeeded"
    },
    "subStatus": null,
    "submissionTimestamp": null,
    "subscriptionId": null,
    "tenantId": null
  }
]

Example 2:

(env) vishrut@usermac azure-cli (implement-activity-logs-filter) $ az monitor activity-logs list -g vishrutrg --status Failed --max-events 2
[
  {
    "authorization": {
      "action": "Microsoft.Resources/deployments/write",
      "role": null,
      "scope": "/subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourcegroups/vishrutrg/deployments/ConfigureVMProtection-2017114141745"
    },
    "caller": "[email protected]",
    "category": {
      "localizedValue": "Administrative",
      "value": "Administrative"
    },
    "claims": {
      "_claim_names": "{\"groups\":\"src1\"}",
      "_claim_sources": "{\"src1\":{\"endpoint\":\"https://graph.windows.net/xxxx-xxxxx-xxxx-xxxxx/users/xxxx-xxxxx-xxxx-xxxxx/getMemberObjects\"}}",
      "appid": "xxxx-xxxxx-xxxx-xxxxx",
      "appidacr": "2",
      "aud": "https://management.core.windows.net/",
      "e_exp": "10800",
      "exp": "1487101508",
      "http://schemas.microsoft.com/claims/authnclassreference": "1",
      "http://schemas.microsoft.com/claims/authnmethodsreferences": "pwd,mfa",
      "http://schemas.microsoft.com/identity/claims/objectidentifier": "xxxx-xxxxx-xxxx-xxxxx",
      "http://schemas.microsoft.com/identity/claims/scope": "user_impersonation",
      "http://schemas.microsoft.com/identity/claims/tenantid": "xxxx-xxxxx-xxxx-xxxxx",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname": "Vishrut",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "[email protected]",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "OiPzuxsuzsOaXhLPWV6ZySW0oTqOri3Nfpxn8qwMR9o",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname": "Shah",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn": "[email protected]",
      "iat": "1487097608",
      "in_corp": "true",
      "ipaddr": "167.220.0.92",
      "iss": "https://sts.windows.net/xxxx-xxxxx-xxxx-xxxxx/",
      "name": "Vishrut Shah",
      "nbf": "1487097608",
      "onprem_sid": "S-1-5-21-2127521184-1604012920-1887927527-16290117",
      "platf": "5",
      "puid": "10033FFF8D9F178A",
      "ver": "1.0"
    },
    "correlationId": "98fc5d6d-f3bb-471e-afd3-94ff29956f43",
    "description": "",
    "eventDataId": "5b09a68d-f63a-4061-9977-c0cdcdba73e2",
    "eventName": {
      "localizedValue": "End request",
      "value": "EndRequest"
    },
    "eventTimestamp": "2017-02-14T19:21:01.172662+00:00",
    "httpRequest": null,
    "id": "/subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourcegroups/vishrutrg/deployments/ConfigureVMProtection-2017114141745/events/5b09a68d-f63a-4061-9977-c0cdcdba73e2/ticks/636226968611726629",
    "level": "Error",
    "operationId": "9278681c-fa53-4dac-89a2-0b3403e5598e",
    "operationName": {
      "localizedValue": "Microsoft.Resources/deployments/write",
      "value": "Microsoft.Resources/deployments/write"
    },
    "properties": null,
    "resourceGroupName": "vishrutrg",
    "resourceId": "/subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourcegroups/vishrutrg/deployments/ConfigureVMProtection-2017114141745",
    "resourceProviderName": {
      "localizedValue": "Microsoft Resources",
      "value": "Microsoft.Resources"
    },
    "resourceType": {
      "localizedValue": "Microsoft.Resources/deployments",
      "value": "Microsoft.Resources/deployments"
    },
    "status": {
      "localizedValue": "Failed",
      "value": "Failed"
    },
    "subStatus": {
      "localizedValue": "",
      "value": ""
    },
    "submissionTimestamp": "2017-02-14T19:21:20.159333+00:00",
    "subscriptionId": "xxxx-xxxxx-xxxx-xxxxx",
    "tenantId": "xxxx-xxxxx-xxxx-xxxxx"
  },
  {
    "authorization": {
      "action": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/write",
      "role": null,
      "scope": "/subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourcegroups/vishrutrg/providers/Microsoft.RecoveryServices/vaults/rsbvault/backupFabrics/Azure/protectionContainers/iaasvmcontainer;iaasvmcontainerv2;vishrutrg;vmtests1/protectedItems/vm;iaasvmcontainerv2;vishrutrg;vmtests1"
    },
    "caller": "[email protected]",
    "category": {
      "localizedValue": "Administrative",
      "value": "Administrative"
    },
    "claims": {
      "_claim_names": "{\"groups\":\"src1\"}",
      "_claim_sources": "{\"src1\":{\"endpoint\":\"https://graph.windows.net/xxxx-xxxxx-xxxx-xxxxx/users/xxxx-xxxxx-xxxx-xxxxx/getMemberObjects\"}}",
      "appid": "xxxx-xxxxx-xxxx-xxxxx",
      "appidacr": "2",
      "aud": "https://management.core.windows.net/",
      "e_exp": "10800",
      "exp": "1487101508",
      "http://schemas.microsoft.com/claims/authnclassreference": "1",
      "http://schemas.microsoft.com/claims/authnmethodsreferences": "pwd,mfa",
      "http://schemas.microsoft.com/identity/claims/objectidentifier": "xxxx-xxxxx-xxxx-xxxxx",
      "http://schemas.microsoft.com/identity/claims/scope": "user_impersonation",
      "http://schemas.microsoft.com/identity/claims/tenantid": "xxxx-xxxxx-xxxx-xxxxx",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname": "Vishrut",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name": "[email protected]",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier": "OiPzuxsuzsOaXhLPWV6ZySW0oTqOri3Nfpxn8qwMR9o",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname": "Shah",
      "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn": "[email protected]",
      "iat": "1487097608",
      "in_corp": "true",
      "ipaddr": "167.220.0.92",
      "iss": "https://sts.windows.net/xxxx-xxxxx-xxxx-xxxxx/",
      "name": "Vishrut Shah",
      "nbf": "1487097608",
      "onprem_sid": "S-1-5-21-2127521184-1604012920-1887927527-16290117",
      "platf": "5",
      "puid": "10033FFF8D9F178A",
      "ver": "1.0"
    },
    "correlationId": "98fc5d6d-f3bb-471e-afd3-94ff29956f43",
    "description": "",
    "eventDataId": "b97e83dd-801e-43f1-a9ee-254fa492e329",
    "eventName": {
      "localizedValue": "End request",
      "value": "EndRequest"
    },
    "eventTimestamp": "2017-02-14T19:20:58.913909+00:00",
    "httpRequest": null,
    "id": "/subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourcegroups/vishrutrg/providers/Microsoft.RecoveryServices/vaults/rsbvault/backupFabrics/Azure/protectionContainers/iaasvmcontainer%3Biaasvmcontainerv2%3Bvishrutrg%3Bvmtests1/protectedItems/vm%3Biaasvmcontainerv2%3Bvishrutrg%3Bvmtests1/events/b97e83dd-801e-43f1-a9ee-254fa492e329/ticks/636226968589139094",
    "level": "Error",
    "operationId": "2c977310-37f2-4bef-bbcd-ff73c426e6b9",
    "operationName": {
      "localizedValue": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/write",
      "value": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems/write"
    },
    "properties": {
      "statusCode": "Conflict",
      "statusMessage": "{\"status\":\"Failed\",\"error\":{\"code\":\"ResourceDeploymentFailure\",\"message\":\"The resource operation completed with terminal provisioning state 'Failed'.\",\"details\":[{\"code\":\"CloudInternalError\",\"message\":\"Microsoft Azure Backup encountered an internal error.\"}]}}"
    },
    "resourceGroupName": "vishrutrg",
    "resourceId": "/subscriptions/xxxx-xxxxx-xxxx-xxxxx/resourcegroups/vishrutrg/providers/Microsoft.RecoveryServices/vaults/rsbvault/backupFabrics/Azure/protectionContainers/iaasvmcontainer;iaasvmcontainerv2;vishrutrg;vmtests1/protectedItems/vm;iaasvmcontainerv2;vishrutrg;vmtests1",
    "resourceProviderName": {
      "localizedValue": "Microsoft.RecoveryServices",
      "value": "Microsoft.RecoveryServices"
    },
    "resourceType": {
      "localizedValue": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems",
      "value": "Microsoft.RecoveryServices/vaults/backupFabrics/protectionContainers/protectedItems"
    },
    "status": {
      "localizedValue": "Failed",
      "value": "Failed"
    },
    "subStatus": {
      "localizedValue": "",
      "value": ""
    },
    "submissionTimestamp": "2017-02-14T19:21:20.159333+00:00",
    "subscriptionId": "xxxx-xxxxx-xxxx-xxxxx",
    "tenantId": "xxxx-xxxxx-xxxx-xxxxx"
  }
]

Example(s):

 az monitor activity-logs list --select authorization status
 az monitor activity-logs list --select authorization status --resource-uri /subscriptions/xxxx-xxxx-xxxx/resourceGroups/vishrutrg/providers/Microsoft.Web/sites/vishrutwebapp
 az monitor activity-logs list -g vishrutrg
 az monitor activity-logs list --resource-provider Microsoft.Web
 az monitor activity-logs list --correlation-id xxxx-xxxx-xxxx
 az monitor activity-logs list -g vishrutrg --status Failed --max-events 2
 az monitor tenant-activity-logs list --resource-provider Microsoft.Web
 az monitor tenant-activity-logs list --select authorization status  --max-events 2

XPlat CLI Reference: https://github.com/Azure/azure-xplat-cli/blob/bea341b53149246fb61b95883aa34b72a7e980f2/lib/commands/arm/insights/insights._js#L33

@troydai @tjprescott @derekbekoe Please review the PR when you get a chance. Thanks!

Copy link

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few changes--a few questions.

return result_time


def list_activity_logs(client, correlation_id=None, resource_group=None, resource_uri=None,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource_uri is not a URI--at least from your example, it is a resource ID.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahaa then i've been calling it wrong at all the places. Let me update that to resource_id


if present_switch > 1:
raise CLIError("'--correlation-id', '--resource-group', '--resource-uri'"
" and '--resource-provider' are optional and mutually exclusive.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A more consistent error string would be: "usage error: [--correlation-id ID | --resource-group NAME | --resource-id ID | --resource-provider PROVIDER]" This fits with the argparse nomenclature and usage string syntax.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

for param in [correlation_id, resource_group, resource_uri, resource_provider]:
present_switch = present_switch + (1 if param else 0)

if present_switch > 1:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could simplify lines 120-124 this with the more Pythonic: if len([x for x in [...] if x]) > 1:

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

formatter=formatter)

if correlation_id:
odata_filters = _process_prameter(odata_filters, 'correlation_id',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo: _process_parameter

Additionally that is not a very descriptive name. Perhaps something like "_build_odata_filter"?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

caller, 'caller')
if status:
odata_filters = _process_prameter(odata_filters, 'status',
status, 'status')

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like all of the validation and filter building can and should be done within a validator. This would make it easier to test with unit tests, which is the direction we will be increasingly moving toward.


def _add_condition_if_present(default_filter, field_label, field_value):
if not field_value:
return default_filter

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What it the purpose of this if "_process_parameter" already throws an error if the thing in question is missing?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup i can just say _add_condition and format as long as we have field_value because function _process_prarameter would have thrown if field_value is not there.

Copy link

@derekbekoe derekbekoe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@vishrutshah
Copy link
Owner Author

@tjprescott I've addressed review comments, let me know how does changes look now :) Thanks!

Copy link

@tjprescott tjprescott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@vishrutshah
Copy link
Owner Author

Thanks for the review guys!!

@vishrutshah vishrutshah merged commit 1c655cc into monitor-cli Mar 2, 2017
@vishrutshah vishrutshah deleted the implement-activity-logs-filter branch March 2, 2017 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants