AZ CLI query filter on multiple properties using && - azure-cli

I am trying to create an az cli query that can evaluate if I am logged into the correct tenant and subscription. I know I have to use the ? and && operators but have not been able to get them in the correct combination yet that will work. When I query for just a single value using the line below, works fine:
az account list --query "[?id=='my_subscription_id']" --output json
But when I try either of the lines below, it tells me it is invalid jmespath_type value:
az account list --query "[?id=='my_subscription_id' && ?tenantId=='my_tenant_id']" --output json
az account list --query "[(?id=='my_subscription_id') && (?tenantId=='my_tenant_id')]" --output json
when I try the line below, it gives me the error ] was unexpected at this time:
az account list --query "[(?id=='my_subscription_id')&&(?tenantId=='my_tenant_id')]" --output json
I know this can be done, just can't seem to find the right mixture yet.
UPDATED INFO:
Upon further testing, I made some progress but still not exactly what I was expecting. Assume that the tenant ID is 123, the subscription ID of the sub I am wanting is ABC and my account also has access to the subscription ID EFG. When running the command below:
az account list --query "[].{subscriptionId:id,tenantId:tenantId}"
I get the output:
{
"subscriptionId": "ABC",
"tenantId": "123"
},
{
"subscriptionId": "EFG",
"tenantId": "123"
}
I would expect that running the command below, would return just the single record that matches:
az account list --query "[?id == 'ABC' && tenantid == '123'].{subscriptionId:id,tenantId:tenantId}" --output json
But, it does not. It returns [].
Running the command below returns the single record that matches both conditions:
az account list --query "[?id == 'ABC' || tenantid == '123'].{subscriptionId:id,tenantId:tenantId}" --output json
Based on the documentation, && is an AND, and || is an OR. I would think when running the command line that has the || in it would return BOTH records but it only returns the one that contains both values.

I am trying to create an az cli query that can evaluate if I am logged
into the correct tenant and subscription.
In fact, one subscription can only trust one tenant, so you can just filter the subscription Id, it will get the only one match tenant ID. Read more details in this blog.
A directory is the Azure AD service and each directory may have one or
more domains. An Azure subscription has a trust relationship with
Azure Active Directory which means that the subscription trusts Azure
AD to authenticate users, services, and devices.
A directory can have many subscriptions associated with it, but only
one tenant. Multiple subscriptions can trust the same Azure AD
directory, but each subscription can only trust a single directory.
In this case, you have known the subscription Id. You also got the output of the subscription id and tenant Id mapping records. You can get accurate results by filtering your subscription Id like this. Or use it as you knew it: az account list --query "[?id=='my_subscription_id']" --output json
Then you can verify if you have logged in the correct tenant.
az account list --query "[].{SubID:id,TenantID:tenantId}[?SubID=='my_subscription_id']" -o table
result

Related

What should be provided as action-name in az-cli command while creating sentinel alert?

I'm trying to create a sentinel alert by using the below az-cli command :
az sentinel alert-rule action create --action-name
--resource-group
--rule-name
--workspace-name
[--etag]
[--logic-app-resource-id]
[--trigger-uri]
Have followed this article but it doesn't have any examples for the command https://learn.microsoft.com/en-us/cli/azure/sentinel/alert-rule/action?view=azure-cli-latest#az-sentinel-alert-rule-action-create
What should be provided as parameter to action-name ?
az sentinel alert-rule action create --action-name
--resource-group
--rule-name
--workspace-name
[--etag]
[--logic-app-resource-id]
[--trigger-uri] ```
Here --eta, --logic-app-resource-id, --trigger-uri paramters are optional where --action-name is the action group name.
For action name, go to the Azure Portal > Monitor > Alerts > Action Groups > create an action group for which resource that alert rules should be created:

Zabbix item name with Key-value

I have created an item. There I execute a command via system.run, which gives me the name,status as a string from a Docker container.
Using preprocessing and REGEX I have separated the two values from one another. I return the second value as Value. This all works.
But now I want to bring the first parameter in the name of the item. In the docu, table it says that it worked with "$1" but not anymore. (https://www.zabbix.com/documentation/current/en/manual/config/items/item)
But currently it is possible to include macros in the name. Maybe this is a possibility?
Translated with www.DeepL.com/Translator (free version)

Azure DevOps user access filtering

We have a requirement in my project where we need to find out the repository access for users in Azure DevOps using cli.
We were able to find out the top-level access for all the users, using this CLI command as provided in the official azure-cli documents.
Command-1
az devops user list --org {Organisation-Name} --query members[].[username,emailid,accesslevel] -o table
The above command returns the following output:
Username EmailId AccessLevel
------------------------------------------
John Doe john.doe#abc.com Basic
Rick Stein rick.stein#abc.com Stakeholder
....
Next using the user's email-id extracted from the list above, we are able to find out the granular level of repository access for each individual user as follows:
Command #2:
az devops user show --org {Organisation Name} --user john.doe#abc.com --query "[Username:user.name,ProjectRepoName:repo.access]"
The corresponding output -
{
"Username": "John Doe",
"ProjectRepoName": [
"Develop.Env1",
"Test.Env3",
"UAT.Env2"
]
}
This activity gives the required data on an individual user level. However, we want the data for all the users that are provided by the user list from command one as mentioned above.
Is there a way in which we can combine both the az devops user list & az devops user show commands in a single command via a script, that would traverse all the users in the user list and for each user, using the show command provide the details of the repo access, that can then be stored as a json/table output?
Note: one approach that we can think of is- to filter out the name/email from the list generated using command-1 and pass that list in the user section of the second command. However, the user section takes only one value at a time so not sure, how can this be achieved using CLI operations.
Any help or suggestions on this is highly appreciated. Thanks in advance.
The resolution of this issue was by using the foreach loop logic and making use of the appropriate format for filtering the output for command one.
The snippet of the working code-
.......
$listOfMails = (az devops user list --org {Organisation-Name} --query members[].emailid -o table)
foreach($email in $listOfEmails)
{
(az devops user show --org {Organisation Name} --user ($email) --query "[Username:user.name,ProjectRepoName:repo.access]")
}
...
This resulted in the successful extraction of data, as per requirement.

AWS ConfigService- how to append account IDs

I am trying to append the list of account Ids since I don't have access to organization, but whenever i am doing it, previous accounts get replaced with new account ID and i only want to append them.
Please let me know how to do it.
aws configservice put-configuration-aggregator --configuration-aggregator-name test-config --account-aggregation-sources "[{\"AccountIds\": [\"xxxxxx\",\"xxxx\"],\"AwsRegions\": [\"us-east-1\"]}]"
From the documentation
accountIds that are passed will be replaced with existing accounts. If you want to add additional accounts into the aggregator, call DescribeAggregator to get the previous accounts and then append new ones.
References :
https://awscli.amazonaws.com/v2/documentation/api/latest/reference/configservice/put-configuration-aggregator.html
So you can first call DescribeAggregator1 to get the previous accounts and store them in some variable.
Then append new accounts to previous accounts variable via jq.
Append JSON Object via jq
Note - I have added links for AWS CLI V2.

JMeter : How to read particular row data in csv file based on a column value and pass value of that column to a sampler?

I am new to Jmeter and doing a POC to do a load test on a web application.
What I am trying to do:
I have a total of 4 user logins(surgeons). Each Login is associated with 'n' number of patients.
I've created 2 CSV files
1. one with the user login and password for surgeons
2. another CSV file that contains the PatientName, PatientID and the Surgeon associated with that Patient like below.
PatientName,PatientId,loginName
Pa1,PID1,user1
Pa2,PID2,user1
Pa3,PID3,user1
Pa4,PID4,user1
Pa5,PID5,user2
Pa6,PID6,user2
Pa7,PID7,user3
Pa8,PID8,user4
My Scenario:
Login as User.
Navigate to Each Patient Dashboard as per their associations.
log out of the application.
My Testplan
Thread Group (4 users, Ramp up time as 1 sec, 1 loop)
-csv1(with username, password )
-Login Page and Navigate to the Main page
- RunTime Controller (To sustain the load of a set amount of time)
-- While Loop(to loop between the patient dashboard of the surgeon/user logged in)
---CSV2 (the data as shown above)
----Navigate to Dashboard
----Navigate to Main
-Log out of the Application
What I want to achieve:
I want to use the single thread group and run it concurrently for all the 4 users. In this process, once the user login, the user should only those patient data from the CSV which are associated.
For Ex:
When the Thread1 is running with User1 login, he should only able to loop through Pa1, Pa2, Pa3, Pa4 users
When the thread2 is running with User2 login, user should only read the Pa5, Pa6 data.
Like this, each user login should only pick those users as per their associations mentioned above.
Is there any way, I can use this single CSV2 file and achieve this task? so that I don't have to create n number of the thread of n numbers of logins with n number CSV files each containing the data specific to the user login.
According to JMeter Test Elements Execution Order
0. Configuration elements
Pre-Processors
Timers
Sampler
Post-Processors (unless SampleResult is null)
Assertions (unless SampleResult is null)
Listeners (unless SampleResult is null)
Being a Configuration Element CSV Data Set Config is initialized once and before anything else therefore you won't be able to use the current variable from 1st CSV Data Set Config in 2nd CSV Data Set Config.
The solution is using __CSVRead() function instead, JMeter Functions are evaluated in the place where they appear in the Test Plan so you can use any hardcoded value or JMeter Variable or another function there.
More information: How to Pick Different CSV Files at JMeter Runtime
1. CSV Data Set Config for Surgeon credentials (loginNameSurgeon & Password)
2. Login Request (take first surgeon credentials from CSV)
3. While ${__jexl3("${loginNameSurgeon}" != "${loginName}")}
a. CSV Data Set Config for patient data w.r.t surgeons (PatientName,PatientId,loginName)
b. If Controller - ${__jexl3("${loginName}" != "<EOF>")} // to check if we have any more loginName left
c. Dashboard request
d. Debug Sampler // Just to validate if the variables are in place.
4. Logout request