How to repeat: // Create below object from CLI ( here it is 5.6.26 instance ) [root@cluster-repo ~]# cat k.sql delimiter // CREATE DEFINER=`root`@`localhost` PROCEDURE `event_hourly`() BEGIN declare interval_,history_,id_,c,min_attempts_2g,min_attempts_3g int; declare max_time long; declare step_ char(64); DECLARE CONTINUE HANDLER FOR 1048,1062 BEGIN update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; END; truncate hourly_steps; # import roaming_out_data hourly data call sd.roaming_out_data_hourly_import(); # update ua_roam_data_out_d table set step_='update ua_roam_data_out_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ua_roam_data_out_d' into interval_,history_,id_; truncate sd.ua_roam_data_out_d; delete from sd.ua_roam_data_out_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)) group by operator; select count(*) from sd.ua_roam_data_out_d_data where sd.ua_roam_data_out_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update ua_roam_data_out_w table set step_='update ua_roam_data_out_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ua_roam_data_out_w' into interval_,history_,id_; truncate sd.ua_roam_data_out_w; delete from sd.ua_roam_data_out_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)) group by operator; select count(*) from sd.ua_roam_data_out_w_data where sd.ua_roam_data_out_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update ua_roam_data_in_d table set step_='update ua_roam_data_in_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ua_roam_data_in_d' into interval_,history_,id_; truncate sd.ua_roam_data_in_d; delete from sd.ua_roam_data_in_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)) group by operator; select count(*) from sd.ua_roam_data_in_d_data where sd.ua_roam_data_in_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update ua_roam_data_in_w table set step_='update ua_roam_data_in_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ua_roam_data_in_w' into interval_,history_,id_; truncate sd.ua_roam_data_in_w; delete from sd.ua_roam_data_in_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)) group by operator; select count(*) from sd.ua_roam_data_in_w_data where sd.ua_roam_data_in_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update ppy_voice_d table set step_='update ppy_voice_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_voice_d' into interval_,history_,id_; truncate sd.ppy_voice_d; delete from sd.ppy_voice_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_voice_d_data where sd.ppy_voice_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update ppy_sms_d table set step_='update ppy_sms_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_sms_d' into interval_,history_,id_; truncate sd.ppy_sms_d; delete from sd.ppy_sms_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_sms_d_data where sd.ppy_sms_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update ppy_ivr_d table set step_='update ppy_ivr_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_ivr_d' into interval_,history_,id_; truncate sd.ppy_ivr_d; delete from sd.ppy_ivr_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_ivr_d_data where sd.ppy_ivr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update ppy_voice_w table set step_='update ppy_voice_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_voice_w' into interval_,history_,id_; truncate sd.ppy_voice_w; delete from sd.ppy_voice_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_voice_w_data where sd.ppy_voice_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update ppy_sms_w table set step_='update ppy_sms_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_sms_w' into interval_,history_,id_; truncate sd.ppy_sms_w; delete from sd.ppy_sms_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_sms_w_data where sd.ppy_sms_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update ppy_ivr_w table set step_='update ppy_ivr_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_ivr_w' into interval_,history_,id_; truncate sd.ppy_ivr_w; delete from sd.ppy_ivr_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_ivr_w_data where sd.ppy_ivr_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update vas_sms_d table set step_='update vas_sms_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_sms_d' into interval_,history_,id_; truncate sd.vas_sms_d; insert into sd.vas_sms_d select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_sms_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_sms_d_data where sd.vas_sms_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update vas_mms_d table set step_='update vas_mms_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_mms_d' into interval_,history_,id_; truncate sd.vas_mms_d; insert into sd.vas_mms_d select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_mms_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_mms_d_data where sd.vas_mms_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update vas_bb_d table set step_='update vas_bb_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_bb_d' into interval_,history_,id_; truncate sd.vas_bb_d; insert into sd.vas_bb_d select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_bb_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_bb_d_data where sd.vas_bb_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update vas_syn_d table set step_='update vas_syn_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_syn_d' into interval_,history_,id_; truncate sd.vas_syn_d; truncate sd.vas_syn_d_data; insert into sd.vas_syn_d_data select timestamp,sum(success),sum(fail),sum(inconclusive) from sd.vas_syn_d_data_work group by timestamp; insert into sd.vas_syn_d select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_syn_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_syn_d_data where sd.vas_syn_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update vas_sms_w table set step_='update vas_sms_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_sms_w' into interval_,history_,id_; truncate sd.vas_sms_w; insert into sd.vas_sms_w select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_sms_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_sms_w_data where sd.vas_sms_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update vas_mms_w table set step_='update vas_mms_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_mms_w' into interval_,history_,id_; truncate sd.vas_mms_w; insert into sd.vas_mms_w select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_mms_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_mms_w_data where sd.vas_mms_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update vas_bb_w table set step_='update vas_bb_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_bb_w' into interval_,history_,id_; truncate sd.vas_bb_w; insert into sd.vas_bb_w select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_bb_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_bb_w_data where sd.vas_bb_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update vas_syn_w table set step_='update vas_syn_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_syn_w' into interval_,history_,id_; truncate sd.vas_syn_w; truncate sd.vas_syn_w_data; insert into sd.vas_syn_w_data select timestamp,sum(success),sum(fail),sum(inconclusive) from sd.vas_syn_w_data_work group by timestamp; insert into sd.vas_syn_w select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_syn_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_syn_w_data where sd.vas_syn_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update voice_2g_cssr_h table set step_='update voice_2g_cssr_h table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_ like '%voice_2g_cssr_h%' into interval_,history_,id_; delete from sd.voice_2g_cssr_h_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'), interval 1 hour)) and attempts>=min_attempts_2g; select count(*) from sd.voice_2g_cssr_h into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update voice_3g_cssr_h table set step_='update voice_3g_cssr_h table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_ like '%voice_3g_cssr_h%' into interval_,history_,id_; delete from sd.voice_3g_cssr_h_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'), interval 1 hour)) and attempts>=min_attempts_3g; select count(*) from sd.voice_3g_cssr_h into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update voice_2g_cdr_h table set step_='update voice_2g_cdr_h table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_ like '%voice_2g_cdr_h%' into interval_,history_,id_; delete from sd.voice_2g_cdr_h_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'), interval 1 hour)); select count(*) from sd.voice_2g_cdr_h into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update voice_3g_cdr_h table set step_='update voice_3g_cdr_h table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_ like '%voice_3g_cdr_h%' into interval_,history_,id_; delete from sd.voice_3g_cdr_h_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'), interval 1 hour)); select count(*) from sd.voice_3g_cdr_h into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update data_pdp_sr_d table set step_='update data_pdp_sr_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='data_pdp_sr_d' into interval_,history_,id_; truncate sd.data_pdp_sr_d; delete from sd.data_pdp_sr_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.data_pdp_sr_d_data where sd.data_pdp_sr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update data_pdp_sr_w table set step_='update data_pdp_sr_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='data_pdp_sr_w' into interval_,history_,id_; truncate sd.data_pdp_sr_w; delete from sd.data_pdp_sr_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.data_pdp_sr_w_data where sd.data_pdp_sr_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update data_web_w table set step_='update data_web_w table'; insert into hourly_steps values(now(),step_); select distinct volume,history from sd.main_kpi where from_='data_web_w' into interval_,history_; truncate sd.data_web_w; insert into sd.data_web_w select 100*avg(page_loadSR),avg(dl_duration) from sd.data_web_sr_w_data,sd.data_web_dl_w_data where sd.data_web_sr_w_data.timestamp=sd.data_web_dl_w_data.timestamp and sd.data_web_sr_w_data.timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select id from sd.main_kpi where from_='data_web_w' and formula='sr as kpi' into id_; select count(*) from sd.data_web_sr_w_data where sd.data_web_sr_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; select id from sd.main_kpi where from_='data_web_w' and formula='dl_duration as kpi' into id_; select count(*) from sd.data_web_dl_w_data where sd.data_web_dl_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update data_web_d table set step_='update data_web_d table'; insert into hourly_steps values(now(),step_); select distinct volume,history from sd.main_kpi where from_='data_web_d' into interval_,history_; truncate sd.data_web_d; insert into sd.data_web_d select 100*avg(page_loadSR),avg(dl_duration) from sd.data_web_sr_d_data,sd.data_web_dl_d_data where sd.data_web_sr_d_data.timestamp=sd.data_web_dl_d_data.timestamp and sd.data_web_sr_d_data.timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select id from sd.main_kpi where from_='data_web_d' and formula='sr as kpi' into id_; select count(*) from sd.data_web_sr_d_data where sd.data_web_sr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; select id from sd.main_kpi where from_='data_web_d' and formula='dl_duration as kpi' into id_; select count(*) from sd.data_web_dl_d_data where sd.data_web_dl_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update 4g_data_web_d table set step_='update 4g_data_web_d table'; insert into hourly_steps values(now(),step_); select distinct volume,history from sd.main_kpi where from_='4g_data_web_d' into interval_,history_; truncate sd.4g_data_web_d; insert into sd.4g_data_web_d select 100*avg(page_loadSR),avg(dl_duration) from sd.4g_data_web_sr_d_data,sd.4g_data_web_dl_d_data where sd.4g_data_web_sr_d_data.timestamp=sd.4g_data_web_dl_d_data.timestamp and sd.4g_data_web_sr_d_data.timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select id from sd.main_kpi where from_='4g_data_web_d' and formula='sr as kpi' into id_; select count(*) from sd.4g_data_web_sr_d_data where sd.4g_data_web_sr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 2 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; select id from sd.main_kpi where from_='4g_data_web_d' and formula='dl_duration as kpi' into id_; select count(*) from sd.4g_data_web_dl_d_data where sd.4g_data_web_dl_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 2 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update 4g_data_web_w table set step_='update 4g_data_web_w table'; insert into hourly_steps values(now(),step_); select distinct volume,history from sd.main_kpi where from_='4g_data_web_w' into interval_,history_; truncate sd.4g_data_web_w; insert into sd.4g_data_web_w select 100*avg(page_loadSR),avg(dl_duration) from sd.4g_data_web_sr_w_data,sd.4g_data_web_dl_w_data where sd.4g_data_web_sr_w_data.timestamp=sd.4g_data_web_dl_w_data.timestamp and sd.4g_data_web_sr_w_data.timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select id from sd.main_kpi where from_='4g_data_web_w' and formula='sr as kpi' into id_; select count(*) from sd.4g_data_web_sr_w_data where sd.4g_data_web_sr_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 2 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; select id from sd.main_kpi where from_='4g_data_web_w' and formula='dl_duration as kpi' into id_; select count(*) from sd.4g_data_web_dl_w_data where sd.4g_data_web_dl_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 2 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update 4g_s1mme_eps_bearer_ca_d table set step_='update 4g_s1mme_eps_bearer_ca_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='4g_s1mme_eps_bearer_ca_d' into interval_,history_,id_; truncate sd.4g_s1mme_eps_bearer_ca_d; insert into sd.4g_s1mme_eps_bearer_ca_d select avg(sr) from sd.4g_s1mme_eps_bearer_ca_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.4g_s1mme_eps_bearer_ca_d_data where sd.4g_s1mme_eps_bearer_ca_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update 4g_s1mme_eps_bearer_ca_w table set step_='update 4g_s1mme_eps_bearer_ca_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='4g_s1mme_eps_bearer_ca_w' into interval_,history_,id_; truncate sd.4g_s1mme_eps_bearer_ca_w; insert into sd.4g_s1mme_eps_bearer_ca_w select avg(sr) from sd.4g_s1mme_eps_bearer_ca_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.4g_s1mme_eps_bearer_ca_w_data where sd.4g_s1mme_eps_bearer_ca_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update data_http_d table set step_='update data_http_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='data_http_d' into interval_,history_,id_; insert into data_http_d_data select unix_timestamp(str_to_date(concat(year(curdate()),'/',data,' ',hour),'%Y/%d/%m %H:%i')), mean_thr_dl from data_http_h_work; delete from sd.data_http_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.data_http_d_data where sd.data_http_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update data_http_w table set step_='update data_http_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='data_http_w' into interval_,history_,id_; insert into data_http_w_data select unix_timestamp(str_to_date(concat(year(curdate()),'/',data,' ',hour),'%Y/%d/%m %H:%i')), mean_thr_dl from data_http_h_work; delete from sd.data_http_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.data_http_w_data where sd.data_http_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update 4g_data_http_d table set step_='update 4g_data_http_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='4g_data_http_d' into interval_,history_,id_; insert into 4g_data_http_d_data select unix_timestamp(str_to_date(concat(year(curdate()),'/',data,' ',hour),'%Y/%d/%m %H:%i')), mean_thr_dl from 4g_data_http_h_work; delete from sd.4g_data_http_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.4g_data_http_d_data where sd.4g_data_http_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update 4g_data_http_w table set step_='update 4g_data_http_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='4g_data_http_w' into interval_,history_,id_; insert into 4g_data_http_w_data select unix_timestamp(str_to_date(concat(year(curdate()),'/',data,' ',hour),'%Y/%d/%m %H:%i')), mean_thr_dl from 4g_data_http_h_work; delete from sd.4g_data_http_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.4g_data_http_w_data where sd.4g_data_http_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update volte_sr_d table set step_='update volte_sr_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_sr_d' into interval_,history_,id_; truncate sd.volte_sr_d; insert into sd.volte_sr_d select sum(success)*100/sum(success+fail+inconclusive) from sd.volte_sr_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_sr_d_data where sd.volte_sr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update volte_reg_d table set step_='update volte_reg_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_reg_d' into interval_,history_,id_; truncate sd.volte_reg_d; insert into sd.volte_reg_d select avg(avgDur) from sd.volte_reg_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_reg_d_data where sd.volte_reg_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update volte_mo_mt_setup_d table set step_='update volte_mo_mt_setup_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_mo_mt_setup_d' into interval_,history_,id_; truncate sd.volte_mo_mt_setup_d; insert into sd.volte_mo_mt_setup_d select avg(avgDur) from sd.volte_mo_mt_setup_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_mo_mt_setup_d_data where sd.volte_mo_mt_setup_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update volte_mo_setup_d table set step_='update volte_mo_setup_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_mo_setup_d' into interval_,history_,id_; truncate sd.volte_mo_setup_d; insert into sd.volte_mo_setup_d select avg(avgDur) from sd.volte_mo_setup_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_mo_setup_d_data where sd.volte_mo_setup_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; # update volte_mt_setup_d table set step_='update volte_mt_setup_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_mt_setup_d' into interval_,history_,id_; truncate sd.volte_mt_setup_d; insert into sd.volte_mt_setup_d select avg(avgDur) from sd.volte_mt_setup_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_mt_setup_d_data where sd.volte_mt_setup_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; END // delimiter ; [root@cluster-repo ~]# mysql -uroot test < k.sql [root@cluster-repo ~]# mysql -uroot test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 20 Server version: 5.6.26-log MySQL Community Server (GPL) Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. ########## Confirm that procedure is valid and created mysql> show procedure status like '%event%'; +------+--------------+-----------+----------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+ | Db | Name | Type | Definer | Modified | Created | Security_type | Comment | character_set_client | collation_connection | Database Collation | +------+--------------+-----------+----------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+ | test | event_hourly | PROCEDURE | root@localhost | 2015-10-07 05:02:01 | 2015-10-07 05:02:01 | DEFINER | | utf8 | utf8_general_ci | latin1_swedish_ci | +------+--------------+-----------+----------------+---------------------+---------------------+---------------+---------+----------------------+----------------------+--------------------+ 1 row in set (0.00 sec) mysql> show create procedure test.event_hourly\G *************************** 1. row *************************** Procedure: event_hourly sql_mode: NO_ENGINE_SUBSTITUTION Create Procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `event_hourly`() BEGIN declare interval_,history_,id_,c,min_attempts_2g,min_attempts_3g int; declare max_time long; declare step_ char(64); DECLARE CONTINUE HANDLER FOR 1048,1062 BEGIN update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; END; truncate hourly_steps; call sd.roaming_out_data_hourly_import(); set step_='update ua_roam_data_out_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ua_roam_data_out_d' into interval_,history_,id_; truncate sd.ua_roam_data_out_d; delete from sd.ua_roam_data_out_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)) group by operator; select count(*) from sd.ua_roam_data_out_d_data where sd.ua_roam_data_out_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update ua_roam_data_out_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ua_roam_data_out_w' into interval_,history_,id_; truncate sd.ua_roam_data_out_w; delete from sd.ua_roam_data_out_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)) group by operator; select count(*) from sd.ua_roam_data_out_w_data where sd.ua_roam_data_out_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update ua_roam_data_in_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ua_roam_data_in_d' into interval_,history_,id_; truncate sd.ua_roam_data_in_d; delete from sd.ua_roam_data_in_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)) group by operator; select count(*) from sd.ua_roam_data_in_d_data where sd.ua_roam_data_in_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update ua_roam_data_in_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ua_roam_data_in_w' into interval_,history_,id_; truncate sd.ua_roam_data_in_w; delete from sd.ua_roam_data_in_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)) group by operator; select count(*) from sd.ua_roam_data_in_w_data where sd.ua_roam_data_in_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update ppy_voice_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_voice_d' into interval_,history_,id_; truncate sd.ppy_voice_d; delete from sd.ppy_voice_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_voice_d_data where sd.ppy_voice_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update ppy_sms_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_sms_d' into interval_,history_,id_; truncate sd.ppy_sms_d; delete from sd.ppy_sms_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_sms_d_data where sd.ppy_sms_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update ppy_ivr_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_ivr_d' into interval_,history_,id_; truncate sd.ppy_ivr_d; delete from sd.ppy_ivr_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_ivr_d_data where sd.ppy_ivr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update ppy_voice_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_voice_w' into interval_,history_,id_; truncate sd.ppy_voice_w; delete from sd.ppy_voice_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_voice_w_data where sd.ppy_voice_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update ppy_sms_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_sms_w' into interval_,history_,id_; truncate sd.ppy_sms_w; delete from sd.ppy_sms_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_sms_w_data where sd.ppy_sms_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update ppy_ivr_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='ppy_ivr_w' into interval_,history_,id_; truncate sd.ppy_ivr_w; delete from sd.ppy_ivr_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.ppy_ivr_w_data where sd.ppy_ivr_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update vas_sms_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_sms_d' into interval_,history_,id_; truncate sd.vas_sms_d; insert into sd.vas_sms_d select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_sms_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_sms_d_data where sd.vas_sms_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update vas_mms_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_mms_d' into interval_,history_,id_; truncate sd.vas_mms_d; insert into sd.vas_mms_d select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_mms_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_mms_d_data where sd.vas_mms_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update vas_bb_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_bb_d' into interval_,history_,id_; truncate sd.vas_bb_d; insert into sd.vas_bb_d select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_bb_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_bb_d_data where sd.vas_bb_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update vas_syn_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_syn_d' into interval_,history_,id_; truncate sd.vas_syn_d; truncate sd.vas_syn_d_data; insert into sd.vas_syn_d_data select timestamp,sum(success),sum(fail),sum(inconclusive) from sd.vas_syn_d_data_work group by timestamp; insert into sd.vas_syn_d select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_syn_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_syn_d_data where sd.vas_syn_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update vas_sms_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_sms_w' into interval_,history_,id_; truncate sd.vas_sms_w; insert into sd.vas_sms_w select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_sms_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_sms_w_data where sd.vas_sms_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update vas_mms_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_mms_w' into interval_,history_,id_; truncate sd.vas_mms_w; insert into sd.vas_mms_w select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_mms_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_mms_w_data where sd.vas_mms_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update vas_bb_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_bb_w' into interval_,history_,id_; truncate sd.vas_bb_w; insert into sd.vas_bb_w select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_bb_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_bb_w_data where sd.vas_bb_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update vas_syn_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='vas_syn_w' into interval_,history_,id_; truncate sd.vas_syn_w; truncate sd.vas_syn_w_data; insert into sd.vas_syn_w_data select timestamp,sum(success),sum(fail),sum(inconclusive) from sd.vas_syn_w_data_work group by timestamp; insert into sd.vas_syn_w select sum(success)*100/sum(success+fail+inconclusive) from sd.vas_syn_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.vas_syn_w_data where sd.vas_syn_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update voice_2g_cssr_h table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_ like '%voice_2g_cssr_h%' into interval_,history_,id_; delete from sd.voice_2g_cssr_h_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'), interval 1 hour)) and attempts>=min_attempts_2g; select count(*) from sd.voice_2g_cssr_h into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update voice_3g_cssr_h table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_ like '%voice_3g_cssr_h%' into interval_,history_,id_; delete from sd.voice_3g_cssr_h_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'), interval 1 hour)) and attempts>=min_attempts_3g; select count(*) from sd.voice_3g_cssr_h into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update voice_2g_cdr_h table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_ like '%voice_2g_cdr_h%' into interval_,history_,id_; delete from sd.voice_2g_cdr_h_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'), interval 1 hour)); select count(*) from sd.voice_2g_cdr_h into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update voice_3g_cdr_h table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_ like '%voice_3g_cdr_h%' into interval_,history_,id_; delete from sd.voice_3g_cdr_h_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'), interval 1 hour)); select count(*) from sd.voice_3g_cdr_h into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update data_pdp_sr_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='data_pdp_sr_d' into interval_,history_,id_; truncate sd.data_pdp_sr_d; delete from sd.data_pdp_sr_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.data_pdp_sr_d_data where sd.data_pdp_sr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update data_pdp_sr_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='data_pdp_sr_w' into interval_,history_,id_; truncate sd.data_pdp_sr_w; delete from sd.data_pdp_sr_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.data_pdp_sr_w_data where sd.data_pdp_sr_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update data_web_w table'; insert into hourly_steps values(now(),step_); select distinct volume,history from sd.main_kpi where from_='data_web_w' into interval_,history_; truncate sd.data_web_w; insert into sd.data_web_w select 100*avg(page_loadSR),avg(dl_duration) from sd.data_web_sr_w_data,sd.data_web_dl_w_data where sd.data_web_sr_w_data.timestamp=sd.data_web_dl_w_data.timestamp and sd.data_web_sr_w_data.timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select id from sd.main_kpi where from_='data_web_w' and formula='sr as kpi' into id_; select count(*) from sd.data_web_sr_w_data where sd.data_web_sr_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; select id from sd.main_kpi where from_='data_web_w' and formula='dl_duration as kpi' into id_; select count(*) from sd.data_web_dl_w_data where sd.data_web_dl_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update data_web_d table'; insert into hourly_steps values(now(),step_); select distinct volume,history from sd.main_kpi where from_='data_web_d' into interval_,history_; truncate sd.data_web_d; insert into sd.data_web_d select 100*avg(page_loadSR),avg(dl_duration) from sd.data_web_sr_d_data,sd.data_web_dl_d_data where sd.data_web_sr_d_data.timestamp=sd.data_web_dl_d_data.timestamp and sd.data_web_sr_d_data.timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select id from sd.main_kpi where from_='data_web_d' and formula='sr as kpi' into id_; select count(*) from sd.data_web_sr_d_data where sd.data_web_sr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; select id from sd.main_kpi where from_='data_web_d' and formula='dl_duration as kpi' into id_; select count(*) from sd.data_web_dl_d_data where sd.data_web_dl_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update 4g_data_web_d table'; insert into hourly_steps values(now(),step_); select distinct volume,history from sd.main_kpi where from_='4g_data_web_d' into interval_,history_; truncate sd.4g_data_web_d; insert into sd.4g_data_web_d select 100*avg(page_loadSR),avg(dl_duration) from sd.4g_data_web_sr_d_data,sd.4g_data_web_dl_d_data where sd.4g_data_web_sr_d_data.timestamp=sd.4g_data_web_dl_d_data.timestamp and sd.4g_data_web_sr_d_data.timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select id from sd.main_kpi where from_='4g_data_web_d' and formula='sr as kpi' into id_; select count(*) from sd.4g_data_web_sr_d_data where sd.4g_data_web_sr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 2 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; select id from sd.main_kpi where from_='4g_data_web_d' and formula='dl_duration as kpi' into id_; select count(*) from sd.4g_data_web_dl_d_data where sd.4g_data_web_dl_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 2 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update 4g_data_web_w table'; insert into hourly_steps values(now(),step_); select distinct volume,history from sd.main_kpi where from_='4g_data_web_w' into interval_,history_; truncate sd.4g_data_web_w; insert into sd.4g_data_web_w select 100*avg(page_loadSR),avg(dl_duration) from sd.4g_data_web_sr_w_data,sd.4g_data_web_dl_w_data where sd.4g_data_web_sr_w_data.timestamp=sd.4g_data_web_dl_w_data.timestamp and sd.4g_data_web_sr_w_data.timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select id from sd.main_kpi where from_='4g_data_web_w' and formula='sr as kpi' into id_; select count(*) from sd.4g_data_web_sr_w_data where sd.4g_data_web_sr_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 2 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; select id from sd.main_kpi where from_='4g_data_web_w' and formula='dl_duration as kpi' into id_; select count(*) from sd.4g_data_web_dl_w_data where sd.4g_data_web_dl_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 2 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update 4g_s1mme_eps_bearer_ca_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='4g_s1mme_eps_bearer_ca_d' into interval_,history_,id_; truncate sd.4g_s1mme_eps_bearer_ca_d; insert into sd.4g_s1mme_eps_bearer_ca_d select avg(sr) from sd.4g_s1mme_eps_bearer_ca_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.4g_s1mme_eps_bearer_ca_d_data where sd.4g_s1mme_eps_bearer_ca_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update 4g_s1mme_eps_bearer_ca_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='4g_s1mme_eps_bearer_ca_w' into interval_,history_,id_; truncate sd.4g_s1mme_eps_bearer_ca_w; insert into sd.4g_s1mme_eps_bearer_ca_w select avg(sr) from sd.4g_s1mme_eps_bearer_ca_w_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.4g_s1mme_eps_bearer_ca_w_data where sd.4g_s1mme_eps_bearer_ca_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update data_http_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='data_http_d' into interval_,history_,id_; insert into data_http_d_data select unix_timestamp(str_to_date(concat(year(curdate()),'/',data,' ',hour),'%Y/%d/%m %H:%i')), mean_thr_dl from data_http_h_work; delete from sd.data_http_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.data_http_d_data where sd.data_http_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update data_http_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='data_http_w' into interval_,history_,id_; insert into data_http_w_data select unix_timestamp(str_to_date(concat(year(curdate()),'/',data,' ',hour),'%Y/%d/%m %H:%i')), mean_thr_dl from data_http_h_work; delete from sd.data_http_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.data_http_w_data where sd.data_http_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update 4g_data_http_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='4g_data_http_d' into interval_,history_,id_; insert into 4g_data_http_d_data select unix_timestamp(str_to_date(concat(year(curdate()),'/',data,' ',hour),'%Y/%d/%m %H:%i')), mean_thr_dl from 4g_data_http_h_work; delete from sd.4g_data_http_d_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.4g_data_http_d_data where sd.4g_data_http_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update 4g_data_http_w table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='4g_data_http_w' into interval_,history_,id_; insert into 4g_data_http_w_data select unix_timestamp(str_to_date(concat(year(curdate()),'/',data,' ',hour),'%Y/%d/%m %H:%i')), mean_thr_dl from 4g_data_http_h_work; delete from sd.4g_data_http_w_data where timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.4g_data_http_w_data where sd.4g_data_http_w_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update volte_sr_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_sr_d' into interval_,history_,id_; truncate sd.volte_sr_d; insert into sd.volte_sr_d select sum(success)*100/sum(success+fail+inconclusive) from sd.volte_sr_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_sr_d_data where sd.volte_sr_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update volte_reg_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_reg_d' into interval_,history_,id_; truncate sd.volte_reg_d; insert into sd.volte_reg_d select avg(avgDur) from sd.volte_reg_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_reg_d_data where sd.volte_reg_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update volte_mo_mt_setup_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_mo_mt_setup_d' into interval_,history_,id_; truncate sd.volte_mo_mt_setup_d; insert into sd.volte_mo_mt_setup_d select avg(avgDur) from sd.volte_mo_mt_setup_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_mo_mt_setup_d_data where sd.volte_mo_mt_setup_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update volte_mo_setup_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_mo_setup_d' into interval_,history_,id_; truncate sd.volte_mo_setup_d; insert into sd.volte_mo_setup_d select avg(avgDur) from sd.volte_mo_setup_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_mo_setup_d_data where sd.volte_mo_setup_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; set step_='update volte_mt_setup_d table'; insert into hourly_steps values(now(),step_); select volume,history,id from sd.main_kpi where from_='volte_mt_setup_d' into interval_,history_,id_; truncate sd.volte_mt_setup_d; insert into sd.volte_mt_setup_d select avg(avgDur) from sd.volte_mt_setup_d_data where timestamp>=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval interval_ day)); select count(*) from sd.volte_mt_setup_d_data where sd.volte_mt_setup_d_data.timestamp=unix_timestamp(date_sub(date_format(now(),'%Y-%m-%d %H:00:00'),interval 1 hour)) into c; if c=0 then begin update sd.main_alerts set alerting_status=1 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; else begin update sd.main_alerts set alerting_status=0 where entity in (select service_name from sd.main_button where kpi_id=id_) and alert_type='missing'; end; end if; END character_set_client: utf8 collation_connection: utf8_general_ci Database Collation: latin1_swedish_ci 1 row in set (0.01 sec) mysql> ## with WB - now try to alter procedure after making changes, observe it complains on syntax issues and changes are not applied