create proc ujo_send_event
@eoid varchar(12),
@joid int,
@job_name varchar(64),
@box_name varchar(64),
@AUTOSERV varchar(30),
@priority int,
@event int,
@status int,
@alarm int,
@event_time_gmt int,
@exit_code int,
@machine varchar(80),
@pid int,
@jc_pid int,
@run_num int,
@ntry int,
@text varchar(255),
@que_priority int
AS
declare @counter varchar(7)
declare @evt_num int
declare @l_instance varchar(4)
declare @l_event_time_gmt int
declare @l_gmt_offset int
declare @job_type char(1)
declare @count int
declare @charpos int
declare @nod_name varchar(65)
declare @nod_ckpt varchar(16)
declare @nod_boot varchar(16)
if (@event = 101 AND
(@status = 1 OR @status = 4 OR @status = 5 OR @status = 6 OR @status = 10))
begin
select @priority = 10
end
begin tran
select @l_instance = str_val from ujo_alamode where type = 'AUTOSERV'
update ujo_next_oid set oid = oid + 1 where field = 'evt_num'
select @evt_num = oid - 1 from ujo_next_oid where field = 'evt_num'
commit
if ( @l_instance != @AUTOSERV OR (@event = 101 AND (@status = 1 OR @status = 3 OR @status = 4 OR @status = 5 OR @status = 6 OR @status = 10)) )
begin
select @l_event_time_gmt = datediff( ss,'01/01/1970', getdate() )
select @l_gmt_offset = int_val from ujo_alamode where type = 'gmt_offset'
select @l_event_time_gmt = @l_event_time_gmt + @l_gmt_offset
if (@event = 101 AND @status = 10)
begin
select @l_event_time_gmt = @l_event_time_gmt + 2
end
end
else
begin
select @l_event_time_gmt = @event_time_gmt
end
if (substring(@eoid, 4, 1) = 'y')
begin
select @charpos = charindex('$$UJM_NODE$$', @text)
if (@charpos != 0)
begin
select @nod_name = substring(@text, @charpos + 12, 65)
select @nod_name = upper(@nod_name)
select @nod_ckpt = substring(@text, @charpos + 77, 16)
select @nod_boot = substring(@text, @charpos + 93, 16)
begin tran
if (select TOP 1 1 from ujo_asbnode where nod_name=@nod_name) = 1
begin
update ujo_asbnode set nod_ckpt=@nod_ckpt, nod_boot=@nod_boot
where nod_name=@nod_name
end
else
begin
insert into ujo_asbnode (nod_name, nod_ckpt, nod_boot)
values (@nod_name, @nod_ckpt, @nod_boot)
end
commit
end
end
if (@event = 12345)
begin
select @event = 101
if (@status = 1 OR @status = 3 OR @status = 4 OR @status = 5 OR @status = 6 OR @status = 8)
begin
select @l_event_time_gmt = @event_time_gmt
end
end
if exists(select eoid from ujo_event where eoid = @eoid) or exists(select eoid from ujo_proc_event where eoid = @eoid)
begin
if exists ( select eoid from ujo_event where eoid = @eoid and
(job_name = @job_name AND event = @event AND status = @status
AND ntry = @ntry ))
or exists ( select eoid from ujo_proc_event where eoid = @eoid and
(job_name = @job_name AND event = @event AND status = @status
AND ntry = @ntry ))
begin
print 'This Event was already here'
return 1
end
select @counter = counter from ujo_last_Eoid_counter
insert ujo_event2
( eoid,stamp,joid,job_name,box_name,AUTOSERV,
priority,event,status,alarm,
event_time_gmt,exit_code,
machine,pid, jc_pid, run_num, ntry, text, que_priority,
evt_num, que_status, que_status_stamp,
counter
)
values ( @eoid, getdate(),@joid,@job_name,@box_name,@AUTOSERV,
@priority,@event, @status,
@alarm, @l_event_time_gmt, @exit_code,
@machine, @pid, @jc_pid, @run_num, @ntry, @text, @que_priority,
@evt_num, 0, getdate(),
@counter )
print 'Detected duplicate event.'
return -1
end
if @run_num = 0 and @joid != 0
begin
select @run_num = run_num
from ujo_job_status
where joid = @joid
if @run_num is NULL
begin
select @run_num = 0
end
end
begin tran
insert ujo_event
( eoid,stamp,joid,job_name,box_name,AUTOSERV,
priority,event,status,alarm,
event_time_gmt,exit_code,
machine,pid, jc_pid, run_num, ntry, text, que_priority,
evt_num, que_status, que_status_stamp )
values ( @eoid, getdate(),@joid,@job_name,@box_name,@AUTOSERV,
@priority,@event, @status,
@alarm, @l_event_time_gmt, @exit_code,
@machine, @pid, @jc_pid, @run_num, @ntry, @text, @que_priority,
@evt_num, 0, getdate() )
if @@rowcount = 1
begin
if ( @event = 106 )
begin
insert ujo_alarm
( eoid,alarm,alarm_time,job_name,joid,
state,state_time,evt_num, event_comment,
len, response )
values ( @eoid,@alarm,@l_event_time_gmt,@job_name,@joid,
43, @l_event_time_gmt, 0, @text,
1, ' ' )
end
commit
return 1
end
commit
return 2
GO
GRANT EXECUTE ON [dbo].[ujo_send_event] TO [ujoadmin]
GO