Forum OpenACS Q&A: Response to UPTIME is no more.

Collapse
Posted by Gaizka Villate on
I'm afraid you need to change a query, too:

In uptime-defs.tcl, you should change:

proc uptime_monitor_list_of_ids {db monitor_ids} {
...
...
set selection [ns_db 0or1row $db "select uu.*,to_char(time_when_first_unreachable,'YYYY-MM-DD HH24:MI:SS') as full_unreachable_time, to_char(sysdate,'YYYY-MM-DD HH24:MI:SS') as full_sysdate, round((sysdate - time_when_first_unreachable)*60*24) as n_minutes_downtime
...

for something like this:

...
...
set selection [ns_db 0or1row $db "select uu.*,to_char(time_when_first_unreachable,'YYYY-MM-DD HH24:MI:SS') as full_unreachable_time, to_char(sysdate(),'YYYY-MM-DD HH24:MI:SS') as full_sysdate, round(date_part('epoch', sysdate() - time_when_first_unreachable)/60) as n_minutes_downtime
from ...

since i think PostgreSQL doesn't have a functino round(interval).

Ah, you should also change every call of sysdate for sysdate() and create the usual openacs replacement for sysdate():

create function sysdate() returns datetime as '
begin
        return ''now'';
end;' language 'plpgsql'; 

And, since i've started writing, i'll also post a possible redefinition for uptime_stale_p:

create function uptime_stale_p (datetime)
returns varchar
as '
declare
        time_when_first_unreachable alias for $1;
begin
        IF time_when_first_unreachable is null
          THEN return ''f'';
        ELSE
            IF time_when_first_unreachable > (sysdate() - 10)
                THEN return ''f'';
            ELSE return ''t'';
            END IF;
        END IF;
        return result;
end;
' language 'plpgsql';

Hope that helps!