?? alert.java
字號(hào):
package com.ideas.alert;
import java.util.Date;
import java.sql.*;
import com.ideas.util.*;
import com.ideas.communicate.*;
import com.ideas.data.DBAccess;
import java.util.*;
public class Alert
{
/**html格式報(bào)警內(nèi)容,同時(shí)擁有幾個(gè)主機(jī),就有幾個(gè)數(shù)組元素*/
public static String[] HtmlContent = new String[Configuration.UnixClientIP.
length];
/**{101}格式報(bào)警內(nèi)容*/
public static String[] TokenContent = new String[Configuration.UnixClientIP.
length];
/**報(bào)警自動(dòng)處理恢復(fù)內(nèi)容*/
public static String[] AutoRunContent = new String[Configuration.UnixClientIP.
length];
/**
*得到客戶化警報(bào)信息,html格式
* @return
*/
public static String getAlertTime(String server,String ipaddress)
{
Vector pgV = DBAccess.getGivingTimesData("select timestamp from sybaselog where server='"+server+"' and ipaddress='" + ipaddress + "' order by timestamp desc", 1);
return (String)pgV.elementAt(0);
}
public static String getMsg(String hostip, String hostname)
{
String date = new Timestamp(new Date().getTime()).toString();
String init = hostname + "(" + hostip + ") 狀態(tài)報(bào)告:";
String msg = init;
if(AlertProperties.isNotAction(AlertProperties.cpu_busy_level))
{ //cpu
try
{
Vector v = DBAccess.getGivingTimesData(
"select idle from cpu where ipaddress='" + hostip +
"' order by id desc",
AlertProperties.cpu_busy_times);
int cputimes = 0;
for(; cputimes < AlertProperties.cpu_busy_times; cputimes++)
{
int busy = 100 - Integer.parseInt( (String)v.elementAt(cputimes));
if(busy > AlertProperties.cpu_busy_min)
{
continue;
}
else
{
break;
}
}
if( (cputimes == AlertProperties.cpu_busy_times))
{
msg += WarningMsg.CPU_MSG;
}
}
catch(NullPointerException ne)
{}
catch(Exception e)
{
System.err.println("在生成\"CPU\"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
}
if(AlertProperties.isNotAction(AlertProperties.pg_use_level))
{ //pg
try
{
String[] value = DBAccess.getLatestData(
"select totalsize,inuse from pg where ipaddress='" + hostip +
"' order by id desc");
if(Integer.parseInt(Tools.findNumberInString(value[1])) * 100 /
Integer.parseInt(Tools.findNumberInString(value[0])) >
AlertProperties.pg_use_min)
{
msg += WarningMsg.PG_MSG;
}
}
catch(NullPointerException e)
{}
catch(Exception e)
{
System.err.println("在生成\"頁(yè)交換空間\"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
}
if(AlertProperties.isNotAction(AlertProperties.disk_io_level))
{ //diskio
try
{
Vector v = DBAccess.getGivingTimesData(
"select act from diskio where ipaddress='" + hostip +
"' order by id desc",
AlertProperties.disk_io_times);
int diskiotimes = 0;
for(; diskiotimes < AlertProperties.disk_io_times; diskiotimes++)
{
float act = Float.parseFloat( (String)v.elementAt(diskiotimes));
if(act > AlertProperties.disk_io_min)
{
continue;
}
else
{
break;
}
}
if(diskiotimes == AlertProperties.disk_io_times)
{
msg += WarningMsg.DISKIO_MSG;
}
}
catch(NullPointerException ne)
{}
catch(Exception e)
{
System.err.println("在生成\"系統(tǒng)硬盤\"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
}
if(AlertProperties.isNotAction(AlertProperties.fs_use_level))
{ //fs
try
{
String[] timestamp = DBAccess.getLatestData(
"select timestamp from fs where ipaddress='" + hostip +
"' order by id desc");
Vector result = DBAccess.getBatchData(
"select used from fs where ipaddress='" + hostip +
"' and timestamp='" + timestamp[0] + "'");
for(int i = 0; i < result.size(); i++)
{
String temp = (String)result.elementAt(i);
int value = Integer.parseInt(temp);
if( (value > AlertProperties.fs_use_min) &&
(AlertProperties.fs_use_level == AlertProperties.WARNING))
{
msg += WarningMsg.FS_MSG;
break;
}
}
}
catch(NullPointerException ne)
{}
catch(Exception e)
{
System.err.println("在生成\"文件系統(tǒng)\"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
if(AlertProperties.isNotAction(AlertProperties.engine_busy_level))
{
try
{ //engine 計(jì)算engine的平均值
Vector timestampV = DBAccess.getGivingTimesData(
"select timestamp from engine where ipaddress='" + hostip +
"' group by timestamp order by id desc",
AlertProperties.engine_busy_times);
int i = 0;
for(; i < timestampV.size(); i++)
{
String timestamp = (String)timestampV.elementAt(i);
Vector usagesV = DBAccess.getBatchData(
"select usages from engine where ipaddress='" + hostip +
"' and timestamp='" + timestamp + "'");
float total = 0;
for(int t = 0; t < usagesV.size(); t++)
{
total += Float.parseFloat( (String)usagesV.elementAt(t));
}
float avg = total / usagesV.size();
if(avg > AlertProperties.engine_busy_min)
{
continue;
}
else
{
break;
}
}
if(i == AlertProperties.engine_busy_times)
{
msg += WarningMsg.ENGINE_MSG;
}
}
catch(NullPointerException ne)
{}
catch(Exception e)
{
System.err.println("在生成\"Sybase Engine\"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
}
}
if(AlertProperties.isNotAction(AlertProperties.Sybase_tranx_level))
{
try
{ //sybtransaction status
String[] timestamp = DBAccess.getLatestData(
"select distinct timestamp from sybtran where ipaddress='" + hostip +
"' order by id desc");
Vector result = DBAccess.getBatchData(
"select runtime from sybtran where ipaddress='" + hostip +
"' and timestamp='" + timestamp[0] + "'");
for(int i = 0; i < result.size(); i++)
{
int status = Integer.parseInt( (String)result.elementAt(i));
if(status > AlertProperties.Sybase_tranx_min)
{
msg += WarningMsg.TRANX_MSG;
break;
}
}
}
catch(NumberFormatException nfe)
{}
catch(NullPointerException ne)
{}
catch(Exception e)
{
System.err.println("在生成\"sybtran\"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
}
if(AlertProperties.isNotAction(AlertProperties.sfs_server_level))
{
try
{ //sfs_server
String[] timestamp = DBAccess.getLatestData(
"select timestamp from cicsfs where ipaddress='" + hostip +
"' order by id desc");
Vector result = DBAccess.getBatchData(
"select status from cicsfs where ipaddress='" + hostip +
"' and timestamp='" + timestamp[0] + "'");
for(int i = 0; i < result.size(); i++)
{
String status = (String)result.elementAt(i);
if(!status.equalsIgnoreCase(AlertProperties.sfs_server_normal))
{
msg += WarningMsg.SFSSERVER_MSG;
break;
}
}
}
catch(NullPointerException ne)
{}
catch(Exception e)
{
System.err.println("在生成\"CICS FS Server\"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
}
if(AlertProperties.isNotAction(AlertProperties.sfs_server_warninglog_level))
{
try
{ //sfs server 的warning數(shù)
String[] warnings = DBAccess.getLatestData(
"select warning from sfserror where ipaddress='" + hostip +
"' order by id desc");
int warning = Integer.parseInt(warnings[0]);
if(warning > AlertProperties.sfs_server_warninglog_min)
{
msg += WarningMsg.SFSSERVER_WARNINGLOG_MSG;
}
}
catch(NullPointerException ne)
{}
catch(Exception e)
{
System.err.println("在生成\"CICS FS Server\"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
}
if(AlertProperties.isNotAction(AlertProperties.sfs_server_errorlog_level))
{
try
{ //sfs server 的error數(shù)
String[] warnings = DBAccess.getLatestData(
"select error from sfserror where ipaddress='" + hostip +
"' order by id desc");
int error = Integer.parseInt(warnings[0]);
if(error > AlertProperties.sfs_server_errorlog_min)
{
msg += WarningMsg.SFSSERVER_ERRORLOG_MSG;
}
}
catch(NullPointerException ne)
{}
catch(Exception e)
{
System.err.println("在生成\"CICS FS Server\"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
}
if(AlertProperties.isNotAction(AlertProperties.region_level))
{
try
{ //cicsregions status
String[] timestamp = DBAccess.getLatestData(
"select timestamp from cicsregions where ipaddress='" + hostip +
"' order by id desc");
Vector result = DBAccess.getBatchData(
"select status from cicsregions where ipaddress='" + hostip +
"' and timestamp='" + timestamp[0] + "'");
for(int i = 0; i < result.size(); i++)
{
String status = ( (String)result.elementAt(i)).trim();
if(!status.equalsIgnoreCase(AlertProperties.region_normal.trim()))
{
msg += WarningMsg.CICSREGIONS_MSG;
break;
}
}
}
catch(NullPointerException ne)
{}
catch(Exception e)
{
System.err.println("在生成\"CICS regions \"警報(bào)數(shù)據(jù)時(shí)產(chǎn)生異常");
e.printStackTrace();
}
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -