Skip to content

Conversation

@vishrutshah
Copy link
Contributor

@vishrutshah vishrutshah commented Feb 1, 2017

This enables support for #1954

Here is the complete set of available commands exposed from azure-mgmt-monitor and azure-monitor python sdk.

Here is the state of each Management command:

Command Tested [Manual] Status Issue Category
log-profiles
create Issue 973 Swagger
delete
show
list
update Issue 973 Swagger
--- --- --- --- ---
alert-rule-incidents
show
list
--- --- --- --- ---
alert-rules
create Issue 971 Issue 11 AutoRest Python-Runtime
delete
show Issue 971 AutoRest
list Issue 970 AutoRest
update Issue 971 Issue 11 AutoRest Python-Runtime
--- --- --- --- ---
service-diagnostic-settings
create Issue 972 Swagger
show
update Issue 972 Swagger
--- --- --- --- ---
autoscale-settings Known Issue in Service Monitor Service
create No
delete No
show No
list No
update No

Here is the state of each Data Plane command:

Command Tested [Manual] Status Issue Category
usage-metrics
list
event-categories
list
events
list Issue 969 Swagger
tenant-events
list Issue 899 Permission
metric-definitions
list
metrics
list

Note: azure-mgmt-monitor is not released as python package yet, once released we'll take our dependency on locally checked-in sdk before merge.

@troydai @derekbekoe & @tjprescott when you get a chance, please have a first quick look. Thanks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this would be a good time to move this utility class into azure.cli.core

Copy link
Member

Choose a reason for hiding this comment

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

I disagree. If done, it should be a separate PR to not make this review more difficult.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense. Then I'd prefer it to refactor once this PR gets in.

@tjprescott tjprescott added the Monitor az monitor label Feb 1, 2017
@tjprescott
Copy link
Member

You need to fix the linter issuer (add "# pylint: skip-file" to any auto-genned SDK) and also add a comment to the PR with the -h output for the most important commands.

Copy link
Member

@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.

Need to see help output for the new commands before approving. Otherwise just some minor things.

Copy link
Member

Choose a reason for hiding this comment

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

These should go in a _client_factory.py file to be consistent with other packages.

Copy link
Member

Choose a reason for hiding this comment

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

Still think the client factories should be in _client_factory.py file.

Copy link
Member

Choose a reason for hiding this comment

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

I disagree. If done, it should be a separate PR to not make this review more difficult.

Copy link
Member

Choose a reason for hiding this comment

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

No other command mentions a "REST API" in the CLI that I know of.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ya that's true..that came from swagger comment...I'll remove it 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated: Update a log profile assigned to Azure subscription

Copy link
Member

Choose a reason for hiding this comment

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

typo: metrics.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Member

Choose a reason for hiding this comment

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

It might make sense to clarify "manage Monitor alert rules" etc. for these commands since the terms are pretty generic and could be confused for other things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated: Commands to manage alerts assigned to Azure resources

Copy link
Member

Choose a reason for hiding this comment

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

The --name parameters here need a values completer within their scope (except for create commands).

Copy link
Member

Choose a reason for hiding this comment

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

--azure-resource-name is pretty verbose. Also, will this accept a name or id? Should it? If so, I would recommend --resource with help text that says "Name or ID of the resource to query." or something to that effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't done tests on autoscale, so i am not sure on whether it can accept ids. So I'll keep this pending until then :)

Copy link
Member

Choose a reason for hiding this comment

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

I recommend you spell out the kwargs like we do in the traditional model. (i.e. type=json.loads, help='blahblah')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool

Copy link
Member

Choose a reason for hiding this comment

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

What's this line used for?
It shouldn't be needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's just a formality though it is not technically needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

Copy link
Member

Choose a reason for hiding this comment

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

This is another way of just doing modpath.format(a, b, c) like in the VM module (https://github.com/Azure/azure-cli/blob/master/src/command_modules/azure-cli-vm/azure/cli/command_modules/vm/commands.py#L19).

I don't really see this implementation as simpler than what's in the VM module as I now have to follow create_service_adapter to see what that does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see but as I am following the flow/structure from azure-cli-sql (as I have understood that flow as of now :)), I'd prefer to keep it same. What's your thought on that?

Copy link
Member

Choose a reason for hiding this comment

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

Please remove if it's not used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@derekbekoe I was thinking that we'll not merge the PR in as it has sdk checked-in. So I was planning to wait until azure-mgmt-monitor releases and then removing sdks and the merging PR.

Let me know if there is way where we still allow merging PRs if sdks are checked-in? If so i'll definitely remove it.

Copy link
Contributor

Choose a reason for hiding this comment

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

No. We should NOT. No matter If azure-mgmt-monitor is released we should not include their source code in our code base.

Copy link
Member

Choose a reason for hiding this comment

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

Okay didn't know you weren't planning on merging this right now.
I've created and added a Do Not Merge label to this PR then.

Copy link
Member

Choose a reason for hiding this comment

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

We have allowed services (KeyVault, IoT, etc.) to merge PRs with embedded clients. DocumentDB was about to earlier this week but the SDK was released so he went ahead and did the import changes.

If something holds up this PR from being merged, it really doesn't need to be the desire to avoid (temporarily) having the SDK code in the module.

@vishrutshah
Copy link
Contributor Author

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor -h

Group
    az monitor: Commands to manage Azure Monitor service.

Subgroups:
    alert-rule-incidents       : Commands to manage alert rule incidents.
    alert-rules                : Commands to manage alert rules.
    autoscale-settings         : Commands to manage autoscale settings.
    event-categories           : Commands to manage event categories.
    events                     : Commands to manage events.
    log-profiles               : Commands to manage log profiles.
    metric-definitions         : Commands to manage metric definitions.
    metrics                    : Commands to manage metrics.
    service-diagnostic-settings: Commands to manage service diagnostic settings.
    tenant-events              : Commands to manage tenant events.
    usage-metrics              : Commands to manage usage matrics.

@vishrutshah
Copy link
Contributor Author

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor alert-rule-incidents -h

Group
    az monitor alert-rule-incidents: Commands to manage alert rule incidents.

Commands:
    list: Gets a list of incidents associated to an alert rule.
    show: Gets an incident associated to an alert rule.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor alert-rules -h

Group
    az monitor alert-rules: Commands to manage alert rules.

Commands:
    create: Creates or updates an alert rule.
    delete: Deletes an alert rule.
    list  : List the alert rules within a resource group.
    show  : Gets an alert rule.
    update: Updates an alert rule.
env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor alert-rules create -h

Command
    az monitor alert-rules create: Creates or updates an alert rule.
        Request method: PUT             Request URI:
        https://management.azure.com/subscriptions/{subscription-id}/resourceGroups/{resource-group-
        name}/providers/microsoft.insights/alertRules/{alert-rule-name}?api-version={api-version}.

Arguments
    --alert-rule-resource-name [Required]: The name of the alert rule.
    --is-enabled               [Required]: The flag that indicates whether the alert rule is
                                           enabled.
    --location -l              [Required]: Location.
    --name -n                  [Required]: The name of the rule.
    --resource-group -g        [Required]: Name of resource group.
    --actions                            : The array of actions that are performed when the alert
                                           rule becomes active, and when an alert condition is
                                           resolved.
    --azure-resource-name                : Azure resource name.
    --condition                          : JSON encoded condition configuration. Use @{file} to load
                                           from a file.
    --description                        : The description of the alert rule that will be included
                                           in the alert email.
    --tags                               : Resource tags.

Global Arguments
    --debug                              : Increase logging verbosity to show all debug logs.
    --help -h                            : Show this help message and exit.
    --output -o                          : Output format.  Allowed values: json, jsonc, list, table,
                                           tsv.  Default: json.
    --query                              : JMESPath query string. See http://jmespath.org/ for more
                                           information and examples.
    --verbose                            : Increase logging verbosity. Use --debug for full debug
                                           logs.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor autoscale-settings -h

Group
    az monitor autoscale-settings: Commands to manage autoscale settings.

Commands:
    create: Creates or updates an autoscale setting.
    delete: Deletes and autoscale setting.
    list  : Lists the autoscale settings for a resource group.
    show  : Gets an autoscale setting.
    update: Updates an autoscale setting.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor autoscale-settings create -h

Command
    az monitor autoscale-settings create: Creates or updates an autoscale setting.

Arguments
    --autoscale-setting-resource-name [Required]: The name of the autoscale setting.
    --location -l                     [Required]: Location.
    --name -n                         [Required]: The autoscale setting name.
    --profiles                        [Required]: The collection of automatic scaling profiles that
                                                  specify different scaling parameters for different
                                                  time periods. A maximum of 20 profiles can be
                                                  specified.
    --resource-group -g               [Required]: Name of resource group.
    --azure-resource-name                       : Azure resource name.
    --enabled                                   : The enabled flag. Specifies whether automatic
                                                  scaling is enabled for the resource. The default
                                                  value is 'true'. Default value: True .  Default:
                                                  True.
    --notifications                             : The collection of notifications.
    --tags                                      : Resource tags.
    --target-resource-uri                       : The resource identifier of the resource that the
                                                  autoscale setting should be added to.

Global Arguments
    --debug                                     : Increase logging verbosity to show all debug logs.
    --help -h                                   : Show this help message and exit.
    --output -o                                 : Output format.  Allowed values: json, jsonc, list,
                                                  table, tsv.  Default: json.
    --query                                     : JMESPath query string. See http://jmespath.org/
                                                  for more information and examples.
    --verbose                                   : Increase logging verbosity. Use --debug for full
                                                  debug logs.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor autoscale-settings list -h

Command
    az monitor autoscale-settings list: Lists the autoscale settings for a resource group.

Arguments
    --resource-group -g [Required]: Name of resource group.
    --filter                      : The filter to apply on the operation. For more information
                                    please see https://msdn.microsoft.com/en-
                                    us/library/azure/dn931934.aspx.

Global Arguments
    --debug                       : Increase logging verbosity to show all debug logs.
    --help -h                     : Show this help message and exit.
    --output -o                   : Output format.  Allowed values: json, jsonc, list, table, tsv.
                                    Default: json.
    --query                       : JMESPath query string. See http://jmespath.org/ for more
                                    information and examples.
    --verbose                     : Increase logging verbosity. Use --debug for full debug logs.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor event-categories -h

Group
    az monitor event-categories: Commands to manage event categories.

Commands:
    list: Get the list of available event categories supported in the Activity Log Service.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor event-categories list -h

Command
    az monitor event-categories list: Get the list of available event categories supported in the
    Activity Log Service.
        The current list includes the following: Aministrative, Security, ServiceHealth, Alert,
        Recommendation, Policy.

Arguments

Global Arguments
    --debug    : Increase logging verbosity to show all debug logs.
    --help -h  : Show this help message and exit.
    --output -o: Output format.  Allowed values: json, jsonc, list, table, tsv.  Default: json.
    --query    : JMESPath query string. See http://jmespath.org/ for more information and examples.
    --verbose  : Increase logging verbosity. Use --debug for full debug logs.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor events -h

Group
    az monitor events: Commands to manage events.

Commands:
    list: Provides the list of events.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor events list -h

Command
    az monitor events list: Provides the list of events.
        The **$filter** is very restricted and allows only the following patterns. - List events for
        a resource group: $filter=eventTimestamp ge '<Start Time>' and eventTimestamp le '<End
        Time>' and eventChannels eq 'Admin, Operation' and resourceGroupName eq
        '<ResourceGroupName>'. - List events for resource: $filter=eventTimestamp ge '<Start Time>'
        and eventTimestamp le '<End Time>' and eventChannels eq 'Admin, Operation' and resourceUri
        eq '<ResourceURI>'. - List events for a subscription: $filter=eventTimestamp ge '<Start
        Time>' and eventTimestamp le '<End Time>' and eventChannels eq 'Admin, Operation'. -List
        events for a resource provider: $filter=eventTimestamp ge '<Start Time>' and eventTimestamp
        le '<End Time>' and eventChannels eq 'Admin, Operation' and resourceProvider eq
        '<ResourceProviderName>'. - List events for a correlation Id: api-
        version=2014-04-01&$filter=eventTimestamp ge '2014-07-16T04:36:37.6407898Z' and
        eventTimestamp le '2014-07-20T04:36:37.6407898Z' and eventChannels eq 'Admin, Operation' and
        correlationId eq '<CorrelationID>'. No other syntax is allowed.

Arguments
    --filter   : Reduces the set of data collected. The syntax allowed depends on the operation. See
                 the operation's description for details.
    --select   : Used to fetch events with only the given properties. The filter is a comma
                 separated list of property names to be returned. Possible values are:
                 authorization, channels, claims, correlationId, description, eventDataId,
                 eventName, eventTimestamp, httpRequest, level, operationId, operationName,
                 properties, resourceGroupName, resourceProviderName, resourceId, status,
                 submissionTimestamp, subStatus, subscriptionId.

Global Arguments
    --debug    : Increase logging verbosity to show all debug logs.
    --help -h  : Show this help message and exit.
    --output -o: Output format.  Allowed values: json, jsonc, list, table, tsv.  Default: json.
    --query    : JMESPath query string. See http://jmespath.org/ for more information and examples.
    --verbose  : Increase logging verbosity. Use --debug for full debug logs.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor log-profiles -h

Group
    az monitor log-profiles: Commands to manage log profiles.

Commands:
    create: Create or update a log profile in Azure Monitoring REST API.
    delete: Deletes the log profile.
    list  : List the log profiles.
    show  : Gets the log profile.
    update: Update a log profile in Azure Monitoring REST API.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor log-profiles create -h

Command
    az monitor log-profiles create: Create or update a log profile in Azure Monitoring REST API.

Arguments
    --locations          [Required]: List of regions for which Activity Log events should be stored
                                     or streamed. It is a comma separated list of valid ARM
                                     locations including the 'global' location.
    --name -n            [Required]: The name of the log profile.
    --storage-account-id [Required]: The resource id of the storage account to which you would like
                                     to send the Activity Log.
    --categories                   : The categories of the logs. These categories are created as is
                                     convenient to the user. Some values are: 'Write', 'Delete',
                                     and/or 'Action.'.
    --retention-policy             : The retention policy for the events in the log.
    --service-bus-rule-id          : The service bus rule ID of the service bus namespace in which
                                     you would like to have Event Hubs created for streaming the
                                     Activity Log. The rule ID is of the format: '{service bus
                                     resource ID}/authorizationrules/{key name}'.

Global Arguments
    --debug                        : Increase logging verbosity to show all debug logs.
    --help -h                      : Show this help message and exit.
    --output -o                    : Output format.  Allowed values: json, jsonc, list, table, tsv.
                                     Default: json.
    --query                        : JMESPath query string. See http://jmespath.org/ for more
                                     information and examples.
    --verbose                      : Increase logging verbosity. Use --debug for full debug logs.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor log-profiles show -h

Command
    az monitor log-profiles show: Gets the log profile.

Arguments
    --name -n [Required]: The name of the log profile.

Global Arguments
    --debug             : Increase logging verbosity to show all debug logs.
    --help -h           : Show this help message and exit.
    --output -o         : Output format.  Allowed values: json, jsonc, list, table, tsv.  Default:
                          json.
    --query             : JMESPath query string. See http://jmespath.org/ for more information and
                          examples.
    --verbose           : Increase logging verbosity. Use --debug for full debug logs.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor metric-definitions -h

Group
    az monitor metric-definitions: Commands to manage metric definitions.

Commands:
    list: Lists the metric definitions for the resource.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor metric-definitions list -h

Command
    az monitor metric-definitions list: Lists the metric definitions for the resource.
        The **$filter** parameter is optional, and can be used to only retrieve certain metric
        definitions. For example, get just the definition for the CPU percentage counter:
        $filter=name.value eq '\Processor(_Total)\% Processor Time'. This $filter is very restricted
        and allows only these 'name eq <value>' clauses separated by or operators. No other syntax
        is allowed.

Arguments
    --resource-uri [Required]: The identifier of the resource.
    --filter                 : Reduces the set of data collected. The syntax allowed depends on the
                               operation. See the operation's description for details.

Global Arguments
    --debug                  : Increase logging verbosity to show all debug logs.
    --help -h                : Show this help message and exit.
    --output -o              : Output format.  Allowed values: json, jsonc, list, table, tsv.
                               Default: json.
    --query                  : JMESPath query string. See http://jmespath.org/ for more information
                               and examples.
    --verbose                : Increase logging verbosity. Use --debug for full debug logs.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor metrics -h

Group
    az monitor metrics: Commands to manage metrics.

Commands:
    list: Lists the metric values for a resource.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor metrics list -h

Command
    az monitor metrics list: Lists the metric values for a resource.
        The $filter is used to reduce the set of metric data returned. Some common properties for
        this expression will be: name.value, aggregationType, startTime, endTime, timeGrain. The
        filter expression uses these properties with comparison operators (eg. eq, gt, lt) and
        multiple expressions can be combined with parentheses and 'and/or' operators. Some example
        filter expressions are: - $filter=(name.value eq 'RunsSucceeded') and aggregationType eq
        'Total' and startTime eq 2016-02-20 and endTime eq 2016-02-21 and timeGrain eq
        duration'PT1M', - $filter=(name.value eq 'RunsSucceeded') and (aggregationType eq 'Total' or
        aggregationType eq 'Average') and startTime eq 2016-02-20 and endTime eq 2016-02-21 and
        timeGrain eq duration'PT1H', - $filter=(name.value eq 'ActionsCompleted' or name.value eq
        'RunsSucceeded') and (aggregationType eq 'Total' or aggregationType eq 'Average') and
        startTime eq 2016-02-20 and endTime eq 2016-02-21 and timeGrain eq duration'PT1M'.

Arguments
    --resource-uri [Required]: The identifier of the resource.
    --filter                 : Reduces the set of data collected. The syntax allowed depends on the
                               operation. See the operation's description for details.

Global Arguments
    --debug                  : Increase logging verbosity to show all debug logs.
    --help -h                : Show this help message and exit.
    --output -o              : Output format.  Allowed values: json, jsonc, list, table, tsv.
                               Default: json.
    --query                  : JMESPath query string. See http://jmespath.org/ for more information
                               and examples.
    --verbose                : Increase logging verbosity. Use --debug for full debug logs.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor service-diagnostic-settings -h

Group
    az monitor service-diagnostic-settings: Commands to manage service diagnostic settings.

Commands:
    create: Create or update new diagnostic settings for the specified resource.
    show  : Gets the active diagnostic settings for the specified resource.
    update: Update diagnostic settings for the specified resource.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor service-diagnostic-settings create -h

Command
    az monitor service-diagnostic-settings create: Create or update new diagnostic settings for the
    specified resource.

Arguments
    --resource-uri [Required]: The identifier of the resource.
    --logs                   : The list of logs settings.
    --metrics                : The list of metric settings.
    --service-bus-rule-id    : The service bus rule ID of the service bus namespace in which you
                               would like to have Event Hubs created for streaming Diagnostic Logs.
                               The rule ID is of the format: '{service bus resource
                               ID}/authorizationrules/{key name}'.
    --storage-account-id     : The resource ID of the storage account to which you would like to
                               send Diagnostic Logs.
    --workspace-id           : The workspace ID (resource ID of a Log Analytics workspace) for a Log
                               Analytics workspace to which you would like to send Diagnostic Logs.
                               Example: /subscriptions/4b9e8510-67ab-4e9a-95a9-e2f1e570ea9c/resource
                               Groups/insights-integration/providers/Microsoft.OperationalInsights/w
                               orkspaces/viruela2.

Global Arguments
    --debug                  : Increase logging verbosity to show all debug logs.
    --help -h                : Show this help message and exit.
    --output -o              : Output format.  Allowed values: json, jsonc, list, table, tsv.
                               Default: json.
    --query                  : JMESPath query string. See http://jmespath.org/ for more information
                               and examples.
    --verbose                : Increase logging verbosity. Use --debug for full debug logs.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor tenant-events -h

Group
    az monitor tenant-events: Commands to manage tenant events.

Commands:
    list: Get the Activity Logs for the Tenant.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor tenant-events list -h

Command
    az monitor tenant-events list: Get the Activity Logs for the Tenant.
        Everything that is applicable to the API to get the Activity Log for the subscription is
        applicable to this API (the parameters, $filter, etc.). One thing to point out here is that
        this API does *not* retrieve the logs at the individual subscription of the tenant but only
        surfaces the logs that were generated at the tenant level. The **$filter** is very
        restricted and allows only the following patterns. - List events for a resource group:
        $filter=eventTimestamp ge '<Start Time>' and eventTimestamp le '<End Time>' and
        eventChannels eq 'Admin, Operation' and resourceGroupName eq '<ResourceGroupName>'. - List
        events for resource: $filter=eventTimestamp ge '<Start Time>' and eventTimestamp le '<End
        Time>' and eventChannels eq 'Admin, Operation' and resourceUri eq '<ResourceURI>'. - List
        events for a subscription: $filter=eventTimestamp ge '<Start Time>' and eventTimestamp le
        '<End Time>' and eventChannels eq 'Admin, Operation'. - List evetns for a resource provider:
        $filter=eventTimestamp ge '<Start Time>' and eventTimestamp le '<End Time>' and
        eventChannels eq 'Admin, Operation' and resourceProvider eq '<ResourceProviderName>'. - List
        events for a correlation Id: api-version=2014-04-01&$filter=eventTimestamp ge
        '2014-07-16T04:36:37.6407898Z' and eventTimestamp le '2014-07-20T04:36:37.6407898Z' and
        eventChannels eq 'Admin, Operation' and correlationId eq '<CorrelationID>'. No other syntax
        is allowed.

Arguments
    --filter   : Reduces the set of data collected. The syntax allowed depends on the operation. See
                 the operation's description for details.
    --select   : Used to fetch events with only the given properties. The filter is a comma
                 separated list of property names to be returned. Possible values are:
                 authorization, channels, claims, correlationId, description, eventDataId,
                 eventName, eventTimestamp, httpRequest, level, operationId, operationName,
                 properties, resourceGroupName, resourceProviderName, resourceId, status,
                 submissionTimestamp, subStatus, subscriptionId.

Global Arguments
    --debug    : Increase logging verbosity to show all debug logs.
    --help -h  : Show this help message and exit.
    --output -o: Output format.  Allowed values: json, jsonc, list, table, tsv.  Default: json.
    --query    : JMESPath query string. See http://jmespath.org/ for more information and examples.
    --verbose  : Increase logging verbosity. Use --debug for full debug logs.

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 1, 2017

(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor usage-metrics -h

Group
    az monitor usage-metrics: Commands to manage usage matrics.

Commands:
    list: The List operation lists the usage metrics for the resource.
(env) vishrut@mac azure-cli-monitor (monitor-cli) $ az monitor usage-metrics list -h

Command
    az monitor usage-metrics list: The List operation lists the usage metrics for the resource.

Arguments
    --resource-uri [Required]: The identifier of the resource.
    --filter                 : The filter to apply on the operation.

Global Arguments
    --debug                  : Increase logging verbosity to show all debug logs.
    --help -h                : Show this help message and exit.
    --output -o              : Output format.  Allowed values: json, jsonc, list, table, tsv.
                               Default: json.
    --query                  : JMESPath query string. See http://jmespath.org/ for more information
                               and examples.
    --verbose                : Increase logging verbosity. Use --debug for full debug logs.

@vishrutshah
Copy link
Contributor Author

@tjprescott & @derekbekoe I have just put some more comments on showing the documentation around commands for the reference. I haven't gone through all your comments but as I go I'll keep fixing them. This is just in case you want to see the commands itself 💯

I'll ping you guys once i fix all the review comments :)

@tjprescott
Copy link
Member

The help text for several of the list commands illustrates a major problem.

First, the text from the SDK is crazily verbose, and we should replace it, but second, we should look at the equivalent Xplat CLI commands to see what convenience arguments they use to build up a filter. We should not simply expose the --filter parameter and tell people to go learn OData. Even if we do expose --filter, we should allow the building of a filter with argument. See the az resource list command for examples of this.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's just a formality though it is not technically needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is duplicate with the sql command module. Consider move it up to the azure-cli-core for reuse.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we should. I'd prefer it to do that refactoring once this PR completes so I don't confuse you guys more on actual PR. Does that seem good?

Copy link
Contributor

Choose a reason for hiding this comment

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

Prefer absolute path

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to azure.cli.command_modules.monitor.validators

Copy link
Contributor

Choose a reason for hiding this comment

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

are these coming from SDK? shall we commit this?

Copy link
Contributor Author

@vishrutshah vishrutshah Feb 3, 2017

Choose a reason for hiding this comment

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

Nope. I will not merge in until azure-mgmt-monitor is released. PR Azure/azure-sdk-for-python#974

Copy link
Contributor

Choose a reason for hiding this comment

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

No. We should NOT. No matter If azure-mgmt-monitor is released we should not include their source code in our code base.

@vishrutshah
Copy link
Contributor Author

@troydai @tjprescott @derekbekoe

I've removed SDK code from the cli and took dependencies on azure-mgmt-monitor version 0.1.0 & azure-monitor version 0.2.0 sdks.

I've also addressed general code review comments except:

  1. As I am following design of azure-cli-sql, we have some design that do not match with the other modules. Example: I do not have _client_factory.py, I follow ParametersContext to register commands, expand arguments and aliasing etc
  2. I did duplicate common code between azure-cli-sql & azure-monitor-cli that will be moved and shared as separate PR
  3. I did not provide very convenience methods around --filter parameters yet. I'd like to provide those convenience as separate PR
  4. I've tested commands manually and currently writing automation tests around it. I can add them here or I can do that separate to make it easier for me and reviewer :)

Let me know what you guys think about new changes and how do we want to proceed.

Thanks!

@vishrutshah
Copy link
Contributor Author

Implement filter for metrics list command PR: vishrutshah#2. Please take a look when you get a chance. Thanks!

Copy link
Contributor

@troydai troydai left a comment

Choose a reason for hiding this comment

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

I'm good.

@tjprescott
Copy link
Member

@vishrutshah which commands remain that have filter building arguments in Xplat but not in this PR?

@vishrutshah
Copy link
Contributor Author

vishrutshah commented Feb 28, 2017

Implement filter for activity-logs list & tenant-activity-logs list command PR: vishrutshah#3. Please take a look when you get a chance. Thanks!

@tjprescott With this PR merged in, we have following 2 commands from management plane left to be simplified for filter:

az monitor alert-rules list
az monitor autoscale-settings list

Implement filter & select in activity-logs and tenant-activity-logs
* Adding scaffold command in autoscale-settings

* Addressing review feedback
@codecov-io
Copy link

codecov-io commented Mar 3, 2017

Codecov Report

❗ No coverage uploaded for pull request base (master@7140ca4). Click here to learn what that means.
The diff coverage is 83.2%.

@@           Coverage Diff            @@
##             master   #1953   +/-   ##
========================================
  Coverage          ?   72.3%           
========================================
  Files             ?     373           
  Lines             ?   20139           
  Branches          ?    2942           
========================================
  Hits              ?   14561           
  Misses            ?    4652           
  Partials          ?     926
Impacted Files Coverage Δ
...-monitor/azure/cli/command_modules/monitor/help.py 100% <100%> (ø)
...nd_modules/azure-cli-monitor/azure/cli/__init__.py 100% <100%> (ø)
...itor/azure/cli/command_modules/monitor/__init__.py 100% <100%> (ø)
...ommand_modules/azure-cli-monitor/azure/__init__.py 100% <100%> (ø)
...onitor/azure/cli/command_modules/monitor/params.py 100% <100%> (ø)
...itor/azure/cli/command_modules/monitor/commands.py 100% <100%> (ø)
...-cli-monitor/azure/cli/command_modules/__init__.py 100% <100%> (ø)
...ure/cli/command_modules/monitor/_client_factory.py 42.85% <42.85%> (ø)
...or/azure/cli/command_modules/monitor/validators.py 50% <50%> (ø)
...onitor/azure/cli/command_modules/monitor/custom.py 68.86% <68.86%> (ø)
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7140ca4...2d48c8e. Read the comment docs.

* Adding unittests for custom monitor commands
* Better assertions
Copy link
Contributor

@troydai troydai left a comment

Choose a reason for hiding this comment

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

mostly questions

timezone: 1970-01-01T00:00:00Z, 1970-01-01T00:00:00-0500
:param str caller: The caller to look for when querying
:param str status: The status value to query (ex: Failed)
:param str max_events: The maximum number of records to be returned by the command
Copy link
Contributor

Choose a reason for hiding this comment

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

why is it str not int?

caller, status)

if max_events:
max_events = int(max_events)
Copy link
Contributor

Choose a reason for hiding this comment

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

can't argparser or validator guarantee it's integer?

'''
formatter = "eventTimestamp ge {} and eventTimestamp le {}"
odata_filters = _validate_time_range_and_add_defaults(start_time, end_time,
formatter=formatter)
Copy link
Contributor

Choose a reason for hiding this comment

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

should time validating be done in validator?



def _activity_logs_select_filter_builder(events=None):
'''Build up select filter string from events
Copy link
Contributor

Choose a reason for hiding this comment

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

use triple double quote for docstring.

* Fix expand parameters bug in util to support any parameters
* Adding --filters into activity-logs & tenant-activity-logs
* Adding --ids support into alert-rules & autoscale-settings' show and delete commands
* ignoring filter for alert-rules and autoscale-settings list
@tjprescott
Copy link
Member

As we discussed Friday, we should close this PR until it is ready to be merged and then either reopen it or open a new one.

@vishrutshah
Copy link
Contributor Author

Closing this PR and sending, new one for the review for partner team.

@vishrutshah
Copy link
Contributor Author

New PR @ #2534

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants