zabbix trigger for difference between 2 values from 2 fields - mysql

I am trying to figure out how to have Zabbix pull values from 2 fields, compare them and trigger if the difference between them exceeds a certain value

If one is always larger than the other and using a threshold of 13:
{host:item1.last()}-{host:item2.last()}>13
If their relative sizes are unknown, cannot think of anything nicer but this:
({host:item1.last()}-{host:item2.last()}>13) or ({host:item2.last()}-{host:item1.last()}>13)

You can collect the two fields as standard items (snmp values, agent values etc), then create a calculated item with their difference and appy to it your triggers.

Related

Working with SSRS dynamic fields

SSRS matrix table is a great way to generate dynamic fields as long as values exist.
However, is there a way to "always" show these dynamic fields even if a value doesn't exist for them? The report field locations varies based on data availability and users have to add missing columns in Excel manually.
Dynamic fields go from 3 to up to 30 (at least for now based on run by values). Adding these values manually would make the report hard to maintain.
The way I have handled for this is in the SQL. I build a table of all the values I will always want, I cross join that table to my final output table and update/insert values where they need to exist. That way I guarantee the rows, and eventually columns in the matrix, exists even if they end up being null.
Does that make sense?
Jesse's solution is a good one, but if for whatever reason you can't or prefer not to change the SQL you can do it in SSRS by forcing a blank value in the cell with a expression like this:
=iif(IsNothing(Fields!.xxx.Value)," ",Fields!.xxx.Value)

how to populate column from the content of other columns after a row is inserted in the same table in mysql

I have a table traffic with 7 columns, namely toll_id, date1, shift, car_single, car_return, car_local and car_total.
How could I populate first 5 columns manually, and then store a value in column car_total, which will be the sum of car_single and car_return?
Here is the image of my table:
Just to add a 3rd and 4th ways of achieving the desired outcome:
If you have at least MySQL v5.7.6, you can use a generated column as car_total.
Alternatively, you can choose not to store car_total at all, but calculate this value on the fly while querying the table.
Having a column to store the results of the calculation is good if you regularly have search based on that field because you can use indexes to speed up the searches. Calculating the results on the fly may be better, if you just need to display the result of the calculation, but there is no need to filter on it.
There are two ways to do this:
Add the logic in the application itself, so that it calculates total before inserting the record. (Recommended)
Write an after insert trigger (http://dev.mysql.com/doc/refman/5.7/en/trigger-syntax.html) which calculates the count when record is inserted.

How to calculate multiple records using post-query in oracle forms

I have multiple number datatype records sorted in Oracle database. I am trying to calculate them to get the result, where I want to display it on DISPLAY_ITEM.
I did database item property: no; and datatype: number
I tried post-query trigger on datablock, then i wrote the trigger:
BEGIN
SELECT sal + allow1 + allow2
INTO :display_item1
FROM employees
EXCEPTION
WHEN no_data_found THEN
:all_allow := 0;;
END;
I got the error
frm-40735; POST-QUERY trigger raised unhandled exception ORA-01422
You can only select 1 row into items. In this case ora-01422 means you got more then 1 row.
The trigger post-query fires for every row, so if you want this to happen for every row just do the count for that row only instead of all rows together.
If you really need to make the count for all those rows you could use the SUM function or so.
If I'm understand you correctly and you want to have one item displaying the total of three different columns in the table this is what I should do. Create three hidden items for columns sal, allow1 and allow2. With hidden items I mean database items that have no canvas specified (a.k.a. NULL canvas items). Then I create a none database item to be be displayed to the user. For this item I then set Calculation Mode property to Formula and the Formula property to ':my_block.sal + :my_block.allow1 and my_block.allow2'.
Alternatively you can use the Post-Query trigger to populate the if we can call it 'formula' item but still you need to return all three columns into separate items. I don't like the use of summary items because that has a slightly different meaning inside forms.
If you don't want to do that and you could possible also built your block on a from clause and there directly in the sql do the computation.
Yet another solution should be to create a database side view to do the computation and create the form block based on the view instead of the table. This is by the way not a bad way of creating forms to separate the form itself from the underlying tables. This giving you freedom to change database structure without invalidating the form.
Many possibilities depending what your needs are but personally I should go for the formula item.

DBGrid - how to show the differnce between a column value in two adjacent rows as another column?

Let's say I record my car's latitude & longitude every minute or so, adding a row to a table each time.
I want to have a DB grid with 4 columns
latitude
longitude
distance since last measurment
curent street address, if known
Number 4, I can try to retrieve from Google Maps and I either get a text or blank, so let's ignore that.
How do I get #3? Should I calculate it in my application or in MySql (using a stored procedure or just a complicated SELECT)?
Whichever answer, can someone provide some sample code, or a link to an example? Google is not my friend today :-(
You can do it either way:
Calculate it in your query, and display it in a calculated column (such as when showing line totals where you're displaying ITEM_PRICE, QUANTITY, ITEM_PRICE * QUANTITY AS LINE_COST.
Calculate it in your application, using a calculated field (double-click the TTable component to open the Fields Editor, add field, set the type to ftCalculated, and write code in the OnCalcEvent for that calculated field.
The first choice is usually preferable, because the DB is usually more efficient at doing those sorts of thing on sets of data than when your code does it by row instead. (Set operations are obviously more efficient than row operations.)
Ken’s answer is goes far as it goes, because the most difficult task of solving your problem is getting data from two rows at the same time in SQL. If you were using Oracle or SQL Server, you could use the analytical/windowing LAG function. With MySQL you have to do it yourself. Here are 2 articles on how to simulate LAG in MySQL
http://www.onlamp.com/pub/a/mysql/2007/03/29/emulating-analytic-aka-ranking-functions-with-mysql.html?page=1
http://explainextended.com/2009/03/12/analytic-functions-optimizing-lag-lead-first_value-last_value/
Plus there are StackOverflow questions on how to get data from the previous row.
How do I lag columns in MySQL?
Calculate delta(difference of current and previous row) in sql
I cannot offer any opinion on any of them because I seldom work with MySQL.

Create ordering in a MySQL table without using a number (because then it's hard to put something in between)

I have a long list of items (say, a few million items) in a mysql table, let's call it mytable and it has the field mytable.itemid.
The items are given an order, and can be re=ordered by the user by drag and drop. If I add a field called mytable.order and just put numbers in them, it creates problems: what if I want to move an item between 2 other items? Then all the order fields have to be updated? That seems like a nightmare.
Is there a (scalable) way to add order to a table that is different from just giving every item a number, order by that, and do loads of SQL queries everytime the order is changed?
You can either create a trigger or stored procedure to resequence the order values appropriately, or drop all the associated records and insert new ones in the new order.
You can use fractions (two integers, i.e. a/b). Always there is at least one rational between two other.