📄 alert.java
字号:
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格式报警内容,同时拥有几个主机,就有几个数组元素*/
public static String[] HtmlContent = new String[Configuration.UnixClientIP.
length];
/**{101}格式报警内容*/
public static String[] TokenContent = new String[Configuration.UnixClientIP.
length];
/**报警自动处理恢复内容*/
public static String[] AutoRunContent = new String[Configuration.UnixClientIP.
length];
/**
*得到客户化警报信息,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 + ") 状态报告:";
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\"警报数据时产生异常");
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("在生成\"页交换空间\"警报数据时产生异常");
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("在生成\"系统硬盘\"警报数据时产生异常");
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("在生成\"文件系统\"警报数据时产生异常");
e.printStackTrace();
}
if(AlertProperties.isNotAction(AlertProperties.engine_busy_level))
{
try
{ //engine 计算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\"警报数据时产生异常");
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\"警报数据时产生异常");
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\"警报数据时产生异常");
e.printStackTrace();
}
}
if(AlertProperties.isNotAction(AlertProperties.sfs_server_warninglog_level))
{
try
{ //sfs server 的warning数
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\"警报数据时产生异常");
e.printStackTrace();
}
}
if(AlertProperties.isNotAction(AlertProperties.sfs_server_errorlog_level))
{
try
{ //sfs server 的error数
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\"警报数据时产生异常");
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 \"警报数据时产生异常");
e.printStackTrace();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -