Está en la página 1de 11

一.模拟 程序

本程序是基于 java socket 的程序,对端口 10009 进行监控,如果有请求信息,就


对请求的客户端写入告警的信息流。
实现的流程如下:
对请求建立线程树组,当有连接到的时候,首先为树组线程的请求发送告警信
息,然后再建立新的请求,并且把新的请求线程放到树组同时发送告警信息 。告
警信息是从文件里面来获取。
代码如下:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.LinkedList;

public class Server extends ServerSocket {


private static ArrayList Threader = new ArrayList();

private static LinkedList Message_Array = new LinkedList();

private static int Thread_Counter = 0;

private static boolean isClear = true;

protected static final int SERVER_PORT = 10009;

protected FileOutputStream LOG_FILE = new FileOutputStream(


"d:/connect.log", true);

public Server() throws FileNotFoundException, IOException {


super(SERVER_PORT);
new Broadcast();
// append connection log
Calendar now = Calendar.getInstance();
String str = "[" + now.getTime().toString()
+ "] Accepted a connection\015\012";
byte[] tmp = str.getBytes();
LOG_FILE.write(tmp);
try {
while (true) {
Socket socket = accept();
new CreateServerThread(socket);
}
} catch (Exception e) {
// TODO: handle exception
} finally {
close();
}
}

public static void main(String[] args) throws IOException {


new Server();
}

class Broadcast extends Thread {


public Broadcast() {
start();
}

public void run() {


while (true) {
if (!isClear) {
for (int i = 0; i < Threader.size(); i++) {
CreateServerThread client =
(CreateServerThread) Threader
.get(i);
client.sendMessage();
isClear = Message_Array.size() > 0 ? false :
true;
}
}
}
}
}

// --- CreateServerThread
class CreateServerThread extends Thread {
private Socket client;

private PrintWriter out;

public void sendMessage() {

try {
FileReader fr = new FileReader("c:\\alerm.txt");// 建立
FileReader 对象,并实例化为 fr
BufferedReader br = new BufferedReader(fr);// 建立
BufferedReader 对象,并实例化为 br
String Line = br.readLine();// 从文件读取一行字符串
// 判断读取到的字符串是否不为空
while (Line != null) {
out.println(Line);// 输出从文件中读取的数据
}
br.close();// 关闭 BufferedReader 对象
fr.close();// 关闭文件
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}

public CreateServerThread(Socket s) throws IOException {


client = s;
out = new PrintWriter(client.getOutputStream(), true);
Threader.add(this);
start();
}

public void run() {


sendMessage();
try {
client.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

二.概述
本 AM 模型是对 Device(Switch)设备实时监控,对出现异常,发出告警信息的
模拟程序。实现的思路如下 在 GAT 中定义 Customized AM 模型,定义告警信息
的解析规则,产生 Customized AM 模型同时安装,在客户端配置 Communication
Server AM 模型,启动模拟设备告警信息程序,在客户端查看告警信息。
三. Class Model

对Device(Switch)进行实时的监控,如果有告警的信息,通过
TCP_CS_AM(Depending on the TCP/IP protocal )从模拟程序传送信息,在
Test_AM进行解析,从而当用Temip客户端浏览告警信息的时候,就可以得到告警
的信息,本模型使用AMH(Asynchronours Message Handler) 来处理告警信息。

Test_AM
Mytarget Devicee

TCP_CS_AM
Test_AM
Switch

AMH ICG
NE1

Device D1

Switch S1

四. Mapping

对于告警信息流解析是通过AMH(Asynchronours Message Handler)的方式来处理


的。流程如下:创建Rule Hieerarchy,分析告警信息的结构,根据告警信息的格式:〈[符〉
告警序号,对象名称,时间,设备类型,告警级别,告警号,告警标志,告警文本 <]符><回车
符><换行符>,把信息字符串根据“,”分解成8行,然后从每一行中信息复制到AM中的

五. Steps
1. 用 GAT 首先建立模型如下
在 GAT 首页定义模型 lyx_target, 依次填写
name,kitName,version,parser,TaraceMode,MgtCode,Description 的信息。

Field Type Description


Name Free The name of the customization (for example, Test_AM). The
text name is used in the name of the AM derived from this
customization (for example, Test_AM_AM).
Kit Free A three character ID code that is used in internal libraries.
name text
Versio Free The version of the customization project. Also used to
n text identify AM kit sub-systems.
Kit Free This field is optional. If set, it must contain only letters,
desc. text digits, blanks and the special characters ‘.’ (dot) ‘-‘ (minus)
and ‘_’ (underscore). It is included in the AM subset
description displayed by the commandsetld –D root-path –i
[subset…].
Parser Radio The Asynchronous Message Parser and the Response
butto Parser can share the same parser definition. If you select
ns Common you are prompted to select which parser is to be
used. Note that if the other parser has a definition it will be
lost. When Common is selected, a frame appears around
both parsers.
Trace Radio When compiling the customization, you can set the level of
Mode butto tracing functionality that will be built into the compiled
ns code. The trace messages are useful during run-time
debugging and analysis, when the actual tracing is
selected using trace masks (refer to the section on
Debugging Using Trace Masks of the OpenView TeMIP
Graphical ASCII Toolkit Configuration and Troubleshooting
Guide). Changingthe trace mode results in all module
components being recompiled when Make AM is next
selected. The trace mode is stored in the environment
variable GAT_MAKETRACEMODE.
1 Normal produces a compromise between performance
and debugging usefulness and is therecommended level
when generating the final runtime kit.
2 Debug includes all trace functionality and should be used
only for debugging, as it can make the Access Module run
more slowly.
3 Limited includes a minimal set of traces in the code,
leading to the best performance during run-time.

然后点击 managemant model 面板启动模型创建窗体。在窗体中首先自动显


示了我们在主窗体定义过的 lyx_Target_AM 的结构模型,包含 AMH,ICG 二
个字类,然后我们可以右键点击可以定义 Device (Switch)模型。
2.制定分割字符串的规则
2.1 定义设备类型 map,
定义告警级别 map

我们的规则就是分解 message,所以利用 split 的操作可以完成操作,首先根据分割符


号把 mssage 分解成 8 行,然后再每一行去获得我们所要得信息,对于告警级别和设
备类型,就可以从我们定义好的 map 中得到信息了
对于分解的规则,GAT 提供了测试的工具,首先要编译要测试的 parser 模块,然后
利用测试的工具来测试规则的正确性
3.安装
To install the AM on the local director, follow this procedure:
13.1. Generate the executable code and configuration files for the AM.
Select AM from the Make menu in GAT's Main Customization Window.
23.2. Update the local TeMIP dictionary with the AM's entity model.
Select Update dictionary from the Make menu.
33.3. Enroll the AM on the local director. Select Enroll AM from the
Make menu.
43.4. Install the AM. Select File install from the Make menu.
Alternatively, you can select the option Complete Install from the Make menu, which
executes all the above steps in turn. If subsequent modifications are made to the
customization, not all the above steps will need to be repeated, depending on the
type and extent of the modifications.
4.安装后在 Temip_client 工具中就可以看到安装的 lyx_target_am

接下来是配置 commucation server AM 在 Temip_Client Tool.

También podría gustarte