trigger firing based on date difference with current date - zabbix

I have an item which is a trap that is returning an Epoch time like so:
1539302400
This represents as 2018-10-11 20:00:00
What I want to be able to do is have a zabbix trigger that if the value on that Epoch time is less than 32 days from the current date to send an alert.
So if the current date is 2018-10-01 20:00:00 I want the trigger to fire, but if the current date is 2018-09-01 20:00:00 then the trigger would not fire.

You can use the fuzzytime() trigger function like so:
fuzzytime(32d)=1

Related

How to automatically set a cell in mySQL if the time is within a current range

is there a functionality in mySQL that automatically updates a value of a cell if the current time is within the range of another cell ( that is time Data type)
Assuming the table
id startTime endTime state
----------------------------------------------
1 13:00:00 15:00:00 3
2 12:00:00 16:00:00 6
I would like the state to change to 0 if the current time (machine local time) is within the start and end time? Is this possible in mySQL or do i have to run and external script?
if this is possible how would i be able to do it ? Thank you
I think that there isn't a function that performed your request. But you can implement a query to do this. You can retrieved current time with command:
select now();
So you can check if the result is in the range

MySQL. How to get o'clock time from hour

I have a time datatype field "MyTimeField" in MySQL. So for example the value can be 10:30:00
I want to select the "o'clock time" in time format, so the output will 10:00:00
tried
TIME_FORMAT(hour(MyTimeField),'%T')
but no luck, this returns 00:00:10
Any ideas?
If you want only the hour you could use
TIME_FORMAT(MyTimeField,'%H:00:00')

split time between start time and end time with one hour interval in mysql

I have start time and end time with time stamp format. Now i want to know how to split time between two things with 60 minutes interval.
I have booking table. so now split the available slots with one hour interval for each date
I have started ,endedslots for booking. For example started is2014-05-02 18:00:00and ended is2014-05-02 22:00:00`. Now I want like this:
START TIME
-------------------
2014-05-02 18:00:00
2014-05-02 19:00:00
2014-05-02 20:00:00
2014-05-02 21:00:00
Try this
SELECT `START_TIME`
FROM TABLE
WHERE `START_TIME` BETWEEN "2014-05-02 18:00:00" AND "2014-05-02 22:00:00"

MySQL custom datetime

I am trying to display data associated with date. However in my case, I don't want the date to start at 00:00:00 and finishes at 23:59:59. Rather I want it to start at 16:00:00 and finishes at 06:00:00 the next day. In other words I want to create a custom time for date.
In the same time I want to GROUP_BY date.
For instance I have these values in the database:
want it to give me:
date: 2013-09-08 count: 2
date: 2013-09-09 count: 1
I am not asking for code, but a way to think about it, or useful methods.
Thank you in advance!
The simplest method is to take the existing date and subtract six hours to get the "effective" date. You would do this for output purposes only.
Example:
select date(datecol - interval 6 hour) as MyDate, count(*)
from t
group by date(datecol - interval 6 hour);
You can use a where clause to remove the times between 6:00 and 16:00 (unless that is a typo).

How do I generate monthly events?

I want to create a monthly event for every registered customer that fires an insert statement on billing table. If an event is specified to run from say 20th Aug 2013 0:00 hrs (a future date), on what date can I expect next event to occur?
I don't know whether to assume it as 30 days or 365/12 days (mathematically).
I am using something like this to create that event:
DELIMITER $$
CREATE EVENT event1
ON SCHEDULE EVERY '1' MONTH
STARTS '2013-08-20 00:00:00'
DO
BEGIN
END$$
DELIMITER ;
My question is when does mysql fire this event in the next month?
Rescheduled events rely on the date interval function of MySQL. Your event would reoccur on:
SELECT DATE_ADD('2013-08-20', INTERVAL 1 MONTH)
that's 2013-09-20.
Fore more details about the date functions, see:
http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add