Alerting on sum of value of two fields in a document using Elast Alert - elastalert

I want to alert on sum of two fields.
Each document will have only one of the two fields.
Ex:
{
"number1" : 30
}
{
"number2": 20
}
Above are the two documents under same index,
I want to alert if sum(sum(number1),sum(number2) in last one hour is less than some value
I have tried the below:
type: metric_aggregation
index: test-*
description: "Testing"
buffer_time:
minutes: 1
timestamp_field: "#timestamp"
doc_type: "doc"
metric_agg_key: number1
metric_agg_key: number2
metric_agg_type: sum
min_threshold: 70
alert:
- "email"
alert_subject: "FNot matching"
alert_text: |
Hi Team,s
alert_text_type: alert_text_only

Related

MongoDB Aggregate $min not calculating

I am using the aggregate:
db.quantum_auto_keys.aggregate([
{$match: {table_name: 'PIZZA_ORDERS'}},
{
$group: {
_id: { onDate: { $dateToString: {format: "%Y-%m-%d", date: '$created_on', timezone: 'America/Los_Angeles'}}, table_name: '$table_name' },
min: { $min: '$last_number' }
}},
{$sort: {_id: 1}}
]);
It ignores the onDate grouping and returns the min for the collection where table_name = PIZZA_ORDERS.
When I use $max it calculates the maximum pizza orders by day. $count also returns the number of orders per day correctly.
How should I go about getting the minimum and maximum values via Aggregate or is there a different way to get that information from my collection?
I updated to MongoDB 4.4 and the table_name was not the correct group. Changing it to include another field got min calculation to be correct.

Can Azure Cosmos DB do this kind of query?

I have a JSON object stored in Azure Cosmos DB, and I'm seeing if there's a way to write workable queries doing basic things like Order By.
The structure looks something like :
[
{
"id":"id1",
"title":"test title",
"dataRecord":{
"version":1,
"dataRecordItems":[
{
"itemTitle":"item title 1",
"type":"string",
"value":"My First Title"
},
{
"itemTitle":"item number",
"type":"number",
"value":1
},
{
"itemTitle":"date",
"type":"date",
"value":"21/11/2019 00:00:00"
}
]
}
},
{
"id":"id2",
"title":"test title again",
"dataRecord":{
"version":1,
"dataRecordItems":[
{
"itemTitle":"item title 2",
"type":"string",
"value":"My Second Title"
},
{
"itemTitle":"item number",
"type":"number",
"value":2
},
{
"itemTitle":"date",
"type":"date",
"value":"20/11/2019 00:00:00"
}
]
}
]
I can use ARRAY_CONTAINS to find objects with a particular value, but I run into all kinds of issues if I try to sort by an the value of an object which has the title of "date".
So, as an example, I'd like to be able to say something like (pseudoish code here):
SELECT * FROM c WHERE
ARRAY_CONTAINS(c.dataRecord.dataRecordItems,
{"itemTitle":"item title 2", "value" : "My Second Title"}, true)
AND
ARRAY_CONTAINS(c.dataRecord.dataRecordItems,{"itemTitle":"item number", "value" : 2}, true)
ORDER BY < *** SOMEHOW GET THE DATE HERE from itemTitle = date ***
Then, in this simple case, I would everything returned, but ordered by date.
Obviously in the future I would be pulling out individual fields, but it's all kind of moot if I can't do the first part.
Just wondering if anyone has any great ideas.
Cheers!
You need to store the date in ISO 8601 format:
Year:
YYYY (eg 1997)
Year and month:
YYYY-MM (eg 1997-07)
Complete date:
YYYY-MM-DD (eg 1997-07-16)
Complete date plus hours and minutes:
YYYY-MM-DDThh:mmTZD (eg 1997-07-16T19:20+01:00)
Complete date plus hours, minutes and seconds:
YYYY-MM-DDThh:mm:ssTZD (eg 1997-07-16T19:20:30+01:00)
Complete date plus hours, minutes, seconds and a decimal fraction of a
second
YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
where:
YYYY = four-digit year
MM = two-digit month (01=January, etc.)
DD = two-digit day of month (01 through 31)
hh = two digits of hour (00 through 23) (am/pm NOT allowed)
mm = two digits of minute (00 through 59)
ss = two digits of second (00 through 59)
s = one or more digits representing a decimal fraction of a second
TZD = time zone designator (Z or +hh:mm or -hh:mm)
https://www.w3.org/TR/NOTE-datetime

Compare two SQL column values in Google Pie Chart

Afternoon all, I'm trying to compare two SQL columns values against each to work out the percentage and then display this output in Google charts
I have the following query..
SELECT Count(lineAudited) as total_count, 121 as total_required FROM SMT_24_Point_Check.dbo.auditRecord which displays two columns, one value is 111 and the second column is 121, therefore the percentage is 91%, When I try to input this query into Google Chart, it's only displaying the second columns value
This displays two columns, one value is 111 and the second column is 121, therefore the percentage is 91%, When I try to input this query into Google Chsart, it's only displaying the second columns value
function drawChartCategory() {
var data = google.visualization.arrayToDataTable([
['total_count', 'total_required'],
<?php
while($row = odbc_fetch_array($result1))
{
echo "['".$row["total_count'"]."', ".$row["total_required"]."],";
}
?>
]);
var options = {
title: 'Total audits completed',
width: 900,
height: 500,
backgroundColor: '#E8E8E8',
pieSliceText: 'value',
is3D: true
};
var chart = new google.visualization.PieChart(document.getElementById('piechartCategory'));
chart.draw(data, options);
}
How can I get it to show a segment of 91% and 9%?
check the data format for a PieChart
there should be two columns for each row / slice.
first column should be a string for the name of the slice,
the second a number for the value.
as such, try formatting your data as follows...
'Required', 111
'Not Required', 10
you cannot add the total as a slice or it will throw off the percentage.
while($row = odbc_fetch_array($result1))
{
echo "['Required', ".$row["total_required"]."],";
echo "['Not Required', ".($row["total_count'"] - $row["total_required"])."],";
}

Sorting by part of a number in datatables

I have a DataTable where my first column is a VIN number.
Example: FLXVU3822G1000013
Now VIN numbers are just a bunch of information tacked together. The last 6 numbers are the sequence number for that year. You can see that this example vehicle is the 13th one of the year. I'd really like to have my list filtered on those last 6 digits. Is there a way to do that?
You can easily solve this by a custom sorting plugin. In fact you just need to extract the last 6 digits and return them as a number, then dataTables will sort the column using the internal number sorting algorithm :
jQuery.extend( jQuery.fn.dataTableExt.oSort, {
"last-6-digits-pre": function ( a ) {
var n = a.substring(a.length - 6, a.length)
return parseInt(n)
}
})
Usage :
var table = $('#example').DataTable({
columnDefs : [
{ targets: 0, type: 'last-6-digits' }
]
})
where targets: 0 is the index of the column you want to be sorted this particular way.
See demo -> http://jsfiddle.net/zhmcLkb9/

Insert date difference field in MS-Word

I need to insert in CV created in MS Word document the age of the people.
I know the birth date of the person.
Is there a way to insert a field that will automatically calculates the age?
Johny Walker, {FIELD=NOW-BIRTHDATE} years.
This is not a 100%, but it may do:
{={ DATE \# "YY" } - { MERGEFIELD DOB \# "YY" } +
{IF { DATE \# "MM" } - { MERGEFIELD DOB \# "MM" } 1 0 }}
Use ctrl+F9 to add the {}, F9 to recalculate and alt+F9 to display the result.