ARM template array parameter - arrays

I have an ARM template with a web app alerting rule, where I want to be able to configure which e-mails get the alerts.
The snippet for the e-mail alerting action is this:
"action": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": false,
"customEmails": [
"email1#example.com",
"email2#example.com"
]
}
The same template is used for setting up production, test, and dev environments. So I would like to use a parameter for the e-mail alerting.
How can I generate an array to be used as the "customEmails" property based on either a comma separated string, or an array type parameter?
I have tried "customEmails": "[array(parameters('AlertEmailRecipients'))]", and also
"customEmails": [
[array(parameters('AlertEmailRecipients'))]
]
but neither work. I don't know how to tell it that the "customEmails" property value should come from a parameter.

I used the following using an array parameter:
parameter declaration:
"customEmails": {
"type": "array",
"metadata": {
"description": "alert email addressess"
}
}
in the parameters file:
"customEmails": {
"value": [
"email1#domain.com",
"email2#domain.com"
]
}
usage:
"customEmails": "[parameters('customEmails')]"

I found a solution. The main problem was that my comma separated list of e-mail addresses had a space after each comma.
The way I have implemented it now is like this:
Define a string parameter with a comma separated list of e-mail addresses. Don't have spaces in the list.
Define a variable like this:
"customEmails" : "[split(parameters('AlertEmailRecipients'), ',')]"
and then reference that variable in the alerting action:
"action": {
"odata.type": "Microsoft.Azure.Management.Insights.Models.RuleEmailAction",
"sendToServiceOwners": false,
"customEmails": "[variables('customEmails')]"
}
The example actually does this, but doesn't make it clear the the list of e-mails can't contain spaces.

Related

access object in array with blanc key in json typescript

I am using storage connector in loopback to load files onto the file system. for every loaded file I am receiving a response like:
{
"files": {
"": [
{
"container": "00003",
"name": "mydoc.docx",
"type": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
"field": "",
"size": 23384
}
]
},
"fields": {}
}
There an issue with the returned array with a key "". The objected containing the above is called loadedFile, say I would like to print the size of the loaded file.
console.log(obj.files.""[0].size);
The above doesn't work as the array doesn't have a name in the response.
Please, can anyone point out to a solution?
Thanks in advance and Regards
T
You can access the property via the Bracket notation, rather than the Dot notation.
In your case:
console.log(obj.files[""][0].size)

Variable pattern in the Watson assistant JSON editor

I've created a pattern for a specific variable in my dialogue.
Type: Pattern ^[A-Za-z]{1,}$
I'd like the value of that variable to be only one word specifically, no more. I just don't know where to insert it in the JSON editor.
{
"output": {
"text": {
"values": [
"Nice to meet you $firstname. How can I assist you mate?"
],
"selection_policy": "sequential"
}
},
"context": {
"firstname": "<? input.text.substring(0, 1).toUpperCase() + input.text.substring(1) ?>"
}
}
If I understand correctly, I think what you want is to create a Pattern based entity with your expression https://cloud.ibm.com/docs/services/assistant?topic=assistant-entities#entities-dictionary-overview
Watson Assistant will identify occurrences of your pattern and store them in the 'entities' array. You can then either build conditions in your dialog nodes using the '#myentitiy' syntax, or access them right from the 'entities' array. If you want just the first occurrence use entities.get(0)

In ibm watson conversation, How to extract a string after a certain word into the context variable?

for e.g. "show me an image of Eiffel tower" ... so i want Eiffel tower to be stored in the variable. that is i want any word after "of" to be stored. how to do this? . Thanks in advance.
Simple way to do this is by creating an entity which contains values like Eiffel Tower. Then you can store that in any context variable.
{
"context": {
"xyz":"#Place"
},
"output": {}
}
Here Place is your entity.You can use your context variable anywhere.
You can use regular expressions to capture entity values from user input. To capture the one or two words after of, use of ([a-z]+\s*[a-z]+) as the regular expression. Regular expressions are called patterns in WCS. Here is how a definition could look:
Then save the what the user says into the context variable using:
{
"context": {
"thing": "<? #thing.groups[1] ?>"
}
}
To test it you can use the context variable in an answer, for example:
{
"output": {
"text": {
"values": [
"Getting a picture of $thing"
]
}
}
}
More information can be found at: https://console.bluemix.net/docs/services/conversation/entities.html#defining-entities

JSON Schema: verifying object's values, without keys

Not to confuse anybody, I'll start with validating arrays...
Regarding arrays, JSON Schema can check whether elements of an (((...)sub)sub)array conform to a structure:
"type": "array",
"items": {
...
}
When validating objects, I know I can pass certain keys with their corresponding value types, such as:
"type": "object",
"properties": {
// key-value pairs, might also define subschemas
}
But what if I've got an object which I want to use to validate values only (without keys)?
My real-case example is that I'm configuring buttons: there might be edit, delete, add buttons and so on. They all have specific, rigid structure, which I do have JSON schema for. But I don't want to limit myself to ['edit', 'delete', 'add'] only, there might be publish or print in the future. But I know they all will conform to my subschema.
Each button is:
BUTTON = {
"routing": "...",
"params": { ... },
"className": "...",
"i18nLabel": "..."
}
And I've got an object (not an array) of buttons:
{
"edit": BUTTON,
"delete": BUTTON,
...
}
How can I write such JSON schema? Is there any way of combining object with items (I know there are object-properties and array-items relations).
You can use additionalProperties for this. If you set additionalProperties to a schema instead of a boolean, then any properties that aren't explicitly declared using the properties or patternProperties keywords must match the given schema.
{
"type": "object",
"additionalProperties": {
... BUTTON SCHEMA ...
}
}
http://json-schema.org/latest/json-schema-validation.html#anchor64

jsonschema: Verifying that an array contains an element, without erroring on other elements

I recently found jsonschema and I've been loving using it, however recently I've come across something that I want to do that I just haven't been able to figure out.
What I want to do is to validate that an array must contain an element that matches a schema, but I don't want to have validation fail on other elements that would be in the list.
Say that I have an array like the following:
arr = [
{"some object": True},
False,
{"AnotherObj": "a string this time"},
"test"
]
I want to be able to do something like "validate that arr contains an object that has a property 'some object' that is a boolean, and error if it doesn't, but don't care about other elements."
I don't want it to validate the other items in the list. I just want to make sure that the list contains an element that matches the schema at least once. I also do not know the order which the elements will arrive in the array.
I've tried this already with a schema like:
{"type": "array",
"items": {
"type": "object",
"properties": {
"tool": {
# A schema here to validate tool
},
"required": ["tool"]
}
}
The problem is that it requires every item in the array to have the property "tool", and not what I actually want.
Any help anyone can give me with this would be much appreciated! I've been stumped on this for a really long time with no forward progress.
Thanks!
I've gotten an answer to this question:
The schema used is (where ... B ... is the schema to require):
{
"type": "array",
"not": {
"items": {
"not": {... B ...}
}
}
}
It basically works out to be something like "Ensure that not (items don't match B)". I'm not 100% clear on why this works the way it does, but it does so I figured I'd share it for posterity.

Resources