Azure common alert schema sets the commonPropertie as "null" - json

Well I will explain all about my case.
Im trying to set up Azure alerts that sends a custom mails, to do so I need a logic app that parse the info about the said alerts.
The problem is, even if I enable the common alert schema, and fill the custom properties field, as you can see in the image.
But what this alert sends to my Logic App in the customProerties field is a Null value, I don't get why.
But more than that, if I disable the common alert schema, the custom properties field will be sent without problems.
I don't understand if common alert schema doesn't allow customProperties, or if Im doing something bad, I need help.
Thanks for read and ask for it if anything of this post is bad explained.

I have just confirmed this issue with Microsoft support.
If I point an Activity Log Alert Rule to an Action Group Webhook with Common Schema enabled then the Custom Properties don't appear in the JSON payload. If I disable the Common Schema then the property does appear in the payload.
If I do the same for a Metric alert or Log Query alert, the Custom Properties do appear at the Webhook endpoint regardless of whether the Common Schema is enabled or not.
Microsoft pointed that the schemas for each type are documented (no custom property on the Activity Log Common Schema) and that this is not a bug. Well... the Alert Rule form does allow to configure the Custom Properties for each type of alert so... ah well, nevermind.
They also said "There are plans to align the behaviour on all alert types including activity logs, although there is no definite ETA though. For now, the best option for you to be able to customize the payloads of activity log alerts is by using logic app as an action group."

Related

Schema update validation fails Azure logic apps

In my Logic app I am using HTTP trigger which fires every 3 hours and using a get request on it. After the API responds, the parse JSON call does schema validation. So far with HTTP trigger and Parse JSON, I don't know a way to disable validation of JSON. I know 'when HTTP request is received' as disable validation option but in my case I don't need 'When http request is recieved', I need HTTP trigger on recurrence basis.
Here are my two questions
1) Is there a way to disable schema validation when using HTTP trigger that fires every so often on recurrence basis?
2)
The API calls that we make to a company, it seems like the company frequently updates their JSON return schema. On Monday the calls were going through correctly, on Tuesday, they were not. Upon asking them, this is their response.
"But almost all changes are "adding", rather than "removing" or "renaming" endpoints and information. I.e. the changes are backward compatible."
My question is adding to schema.. is the validation supposed to fail upon addition because logic app for sure is not validating their additions whereas their representative makes it sound like 'adding' should be backwards compatible. Do addition in schema's cause validation to fail?
I am learning Azure logic apps and not familiar with all components at hand.
What is the best way to handle JSON parsing in case schema changes frequently and how to turn it off if that is a solution.
In your second screenshot, it seems there is nothing to do with the "HTTP Trigger". The problem is caused by the schema in "Parse JSON"(Parse Organization and Group Information) action. You need to confirm with the company and unify the structure of the json data with them.
In your first screenshot, I think you need to confirm with the company if they have the array in the response json data. Apart from this, we can judge if the array exists and then do the "Select" action, shown as below:
The fx expression in the "Condition" is:
empty(body('Parse_JSON')?['array'])
Hope it helps~

How can I tell whether a web service is "Restful" (as it claims to be)?

I am trying to work with a service that its creators describe as "restful"
To make a request to this service I have to post some Json e.g.
{
"#type" : "Something"
"$value" : 1
}
This is posted to a URL similar to this;
https://someSite.com/api/query/execute
No matter what the nature of the request, whether I am retrieving info, adding or updating it I must always use this URL (along with some header values to verify my credentials). The effects of posting to this service are determined by the JSON I send.
Depending on the nature of the call I will receive some JSON very similar to the sample above. This JSON never includes another URL (or part of one). It is always a "data object" i.e. a set of properties and their values. Sometimes I receive an empty response but know that the request has had an effect because I can view those effects through a website provided by the service provider
I have particular issues with ENUM values that I must send because I have no idea of the allowed values (they are always passed as strings)
No documentation has been provided for this service.
I am relatively new to RESTful services and JSON and would like to know whether this is truly a restful service, and if not why not?
Due to my lack of experience in this area I may have omitted some important information that would be required to properly answer this question. I will watch the comments closely and try to provide any additional clarification requested
know whether this is truly a restful service, and if not why not?
It isn't.
One of the main principles of REST is that "things" are identified by URLs. Having a single URL for all interaction with the API violates that principle.

How to get default values on a form submitted via rest?

I'm surprised this hasn't been asked already. I have a form on a web page which is being submitted via a restful web service (it's actually using angular js). The question is how should I set default values on the form? (This is for creates as obviously on an edit I'll be getting values from the server anyway)
An example
Let's say we have a checkbox on the form to opt in/out of marketing emails.
I would like to receive marketing emails [x]
In this case the checkbox is defaulted to checked so they have to physically opt out. In the old world of generating html on the server I probably would have returned these defaults from the business layer and then generated the form html with the defaults set.
Solution 1
Set the default values in the client. As I'm using angular I could have a JS object that represents the default state of the form and use this to initialize the form on a create.
My problem with this approach is that it just feels a bit wrong to be putting business rules like this in the client.
Solution 2
Another option might be to hide fields that have default values and only let them be changed on an edit. This might be ok for some types of field but for our optin field they definitely need to review this. This could be done if the form initially displayed those fields without defaults, then when you click a button to continue the form is saved. The client could then do a get on the object just saved and display all fields with the now populated defaults.
I can't decide if I like this approach or not. It's more requests to the server so in that respect it's not very efficient. Depending on which fields have defaults it might look a bit odd suddenly being presented with some extra fields.
Solution 3
Finally we could create a rest web service to get the default state. I haven't seen any other examples of this so not sure of any conventions. Something like:
GET http://server/rest/myresource/default
Are there any conventions on this kind of thing? Something I've missed? Anyone done this themselves and found a way that works best?
Thanks
If you are talking about an editing form, you have some "defaults" (i.e. the already saved data) and the data that the user is inserting. So you basically get the data (via $http) and use it for extend the form fields (via angular.extend). Here is a fiddle which explains it better: http://jsfiddle.net/F9rD8/
After reading through your comments, I think the problem might be thinking of Angular framework as Presentation Layer. Yes - It is a client side framework, but when running on the client side, Angular provides the MVC Presentation Layer. The recommendation is to augment the presentation layer with Angular "Services".
You might want to have an Angular Business "Service" that provides the defaults for the new form.
In the Angular world, your Layered architecture is essentially on the client side with Views and Controllers forming the presentation layer and both client side angular services and Server side APIs forming the business layer.
Angular services - https://docs.angularjs.org/guide/services
Hope that makes sense.

Customizing json rendering for sling's userManager

I am trying to build my application's admin UI using sling's userManager REST interface, but I would like to customize the json rendering. For example, I would like the response of "Get group" to include the members only if the requestor is a member.
I started by adding libs/sling/group/json.esp but I don't understand how I can get hold of the default response and customize it. Even if I had to query and form the json from scratch, where can I find information about APIs available to get this data from JCR/Sling?
I found that I could use ResourceTraversor to dump the resource object in json form but using new Packages.org.apache.sling.servlets.get.impl.helpers.ResourceTraversor(-1, 10000, resource, true) in the esp throws up an error
There are a few things to note here.
First, you should avoid putting your code under the libs directory. Your app code should live under the apps directory. When attempting to resolve a servlet for a URI, Sling will check apps before it checks libs so if you need to completely override functionality delivered with Sling, you would place your code in apps.
Second, what is (probably, depending on how you have things setup) happening when you request http://localhost:8080/system/userManager/group/administrators.tidy.1.json is the request is being handled by Sling's default GET servlet, because it finds no other script or servlet which is applicable. For research purposes it might be worth looking at the code for the default get servlet, org.apache.sling.servlets.get.impl.DefaultGetServlet, to see what it's using to render JSON. If you need to handle the rendering of a user group in a manner different than what the default GET servlet is doing, then you would need to create a servlet which is listening for requests for resources of type sling/group. It would probably be ideal to create a servlet for this purpose and register it with OSGI. http://sling.apache.org/site/servlets.html provides the various properties you would need to set to ensure the servlet resolver finds your servlet. Your servlet then would handle the request and as such would have direct and easy access to the requested resource.
Third, the particular need you specified is that you do not want the group members to render unless the requesting user is a member of the group requested. This is more of an access control issue than a rendering issue. Sling and Jackrabbit, out of the box, make as few assumptions as possible concerning how you might want your application to be setup. That being the case, you need to establish the access controls that are applicable for your particular use case. The wiki post on Access Control in the Jackrabbit wiki ( http://wiki.apache.org/jackrabbit/AccessControl ) goes into this to an extent.
Using directions from Paul Michelotti's answer, I researched further and found a suitable solution to my problem.
Sling accepts request filters (javax.servlet.Filter) through SCR annotations like the one below
#SlingFilter(scope = SlingFilterScope.REQUEST, order = Integer.MIN_VALUE)
Every request is passed down to the filter before it is processed by the servlet. Using the resourceType, I was able to distinguish requests to group.1.json and group/mygroup.1.json. Since the filter also has access to the current user, I was able to decide to deny the request if it did not abide by my security model and return a 404 status code.
Please refer to this page for details on filters. You can also check out the sample project urlfilter for directions on usage.

Hoping to port a working jQuery Validator implementation's rules to JSONSchema

I'm attempting to move an existing (and working) client-side jQuery validation schema to JSONSchema to allow myself to validate arbitrary JSON on both the client and server.
My application is essentially a bunch of gigantic forms with lots of complex logic determining which questions should be asked based on the user's response to other questions. The forms each have over 200 fields.
Right now I'm only doing client-side validation and that works well about 99% of the time. Browser issues have cropped up on a few occasions, but nothing catastrophic. That being said, I want to do server-side validation (!).
After reading the JSONSchema draft and browsing around some of the v3 implementations, it seems like I might lose some of the more complex rules that my application has come to depend upon. I want to be sure that I'm not missing something before moving too far in any direction.
Some examples:
"If x == 10, then y is required, otherwise it's optional"
10 could be a literal value, an enum, etc., but I need to be able to reference another field in the same structure and guarantee it's value not only exists, but is equivalent to a specific type / value.
I think this is addressed in this thread on the JSONSchema list.
"If x = today's date, and y = tomorrow's date, then x > y"
This logic will be used to ensure that the "from" date comes before the "to" date.
From what I can see there's nothing like this and the only way I can see doing it is passing in a freshly eval-ed chunk of JSON as the schema.
The closest thing I've found to meet the above needs is CERNY.
If I'm barking up the wrong tree, please let me know. I'm also looked into running backbone.js on both the client and server.
tl;dr;
I want to maintain one set of validation rules for large and complex forms and apply these validation rules to arbitrary JSON documents on both the client and server side.
there is many tricks but not all of them are possible. For example
if x == 10 then y is required can be achieved with something like (draft 3):
"type":[
{"properties":{"x":{"enum":[10]}, "y":{"required":true}}},
{"properties":{"x":{"disallow":[{"enum":[10]}]}}}
]
Let's say, it's possible but very tricky… a schema is basically supposed to validate the structure, not it's content (even if there is few properties for this)
Another possible way I personally do like is to "extend" the current validation graph with an external url based schema. The idea is to send parameters of the current document on an url which one will return a relevant schema according to those parameters.
Example:
{
"extends":{"$ref":"http://checkCustomValidity/{x}/{y}/"};
}
Where at "runtime" the schema sent back could be a {"disallow":"any"} if not allowed or {} if ok
This is useful as the url can be both used for the client and server side (your client will not be completely standalone but in some cases, you just cannot)
A real life usage for this is in cases where it is obliged to use a remote service. For example if I do have to check if my nickname is already used on the server during the registration. I code a server side web service answering to the request path: http://www.server.com/isNicknameUsed/{nickname}