Skip to main content
yferreira
New Member
September 8, 2015
Solved

Dataset: Get Interval

  • September 8, 2015
  • 8 replies
  • 12516 views

Hi,

I was trying to figure out how I can subtract "from_dtime(dtime)" of "now()" and count the interval in days.

I was wondering if somebody knows.

Tks folks.

Best answer by hzhao_FTNT

AFAIK, it is not possible to do it, chart can not automatically change column number or customize "No matching log data for this report".

8 replies

hzhao_FTNT
Staff
Staff
September 8, 2015

Hi, we have predefined $day_of_month and $day_of_week, please check it out.

 

Regards,

hz

yferreira
yferreiraAuthor
New Member
September 8, 2015

I'm trying to do something like that:

 

select now() - from_dtime(dtime) as interval, devid, msg from $log where msg like 'Fortigate started' and subtype='system' and level='information' and msg is not null ORDER BY interval DESC limit 1

 

But when I print "now()", I'm getting a date without timezone.

hzhao_FTNT
Staff
Staff
September 8, 2015

I see, then pls try  to_char((now() - from_dtime(dtime)), 'DD') as interval

yferreira
yferreiraAuthor
New Member
September 8, 2015

Great!

It worked really fine.

yferreira
yferreiraAuthor
New Member
September 8, 2015

Another doubt...

How can I ignore "Time Period" ?

hzhao_FTNT
Staff
Staff
September 8, 2015

$filter contains device and time filter, do not recommend to ignore it.

yferreira
yferreiraAuthor
New Member
September 8, 2015

It's because I need to search for every single log message referring to the "Fortigate started", regardless of the "Time Period" setted.

 

Any ideas? 

hzhao_FTNT
Staff
Staff
September 9, 2015

Hi, I think you can select "custom..." for a longer time period.

 

hz

yferreira
yferreiraAuthor
New Member
September 10, 2015

Ok. The query looked like this:

 

select to_char( (now() - from_dtime(dtime) ), 'DD') as interval, devid, msg from $log where msg like 'Fortigate started' and subtype='system' and level='information' and msg is not null and $filter ORDER BY interval ASC limit 1

 

Is possible to create a condition, for example, if the Days be more than 90 days or N/A then print 'More than 90 days' instead of printing the number of the days? But if it less than 90 days, keep showing in Days.

hzhao_FTNT
Staff
Staff
September 10, 2015

Please try: 

select (case when  (date(now()) - date(from_dtime(dtime))) > 90 then 'More than 90 days' else to_char( (now() - from_dtime(dtime) ), 'DD') end) as interval, devid, msg from $log where msg like 'Fortigate started' and subtype='system' and level='information' and msg is not null and $filter ORDER BY interval ASC limit 1

 

regards,

hz

yferreira
yferreiraAuthor
New Member
September 10, 2015

It worked fine.

But if I can't find anything, I would like to print "More than 90 days".

hzhao_FTNT
Staff
Staff
September 10, 2015

then:

select (case when  (date(now()) - date(from_dtime(dtime))) < 90 then to_char( (now() - from_dtime(dtime) ), 'DD')  else 'More than 90 days' end) as interval, devid, msg from $log where msg like 'Fortigate started' and subtype='system' and level='information' and msg is not null and $filter ORDER BY interval ASC limit 1

yferreira
yferreiraAuthor
New Member
September 10, 2015

Good point.

So, I'll remove "and msg is not null".

But, I'm still wondering if could be possible to print a message if we didn't find anything.

hzhao_FTNT
Staff
Staff
September 10, 2015

AFAIK, it is not possible to do it, chart can not automatically change column number or customize "No matching log data for this report".