Archive

‘Programmer’ 分类存档

INSTALL CISCO WAE 6.4.5

Introduction

After installed Centos 6.7 for CISCO WAE, I found python version is 2.6 that is much older, and I need ansible1.9, but Centos default upgrade to ansible2.2… in order to easy management ansible1.9 that is python package, I plan to install PIP. From official website, suggest not use 2.6 under pip, so I need to upgrade python to 2.7 too.

But I found WAE use 2.6 after I succeed upgrade python to 2.7…Summarized the totally steps that will help me review in future.

Upgrade Python

After checked from follow link, python 2.7.9 integrate pip, so install this version 🙂
https://pip.pypa.io/en/latest/installing/

1. Install some package that require by python

python have multi dependencie

[root@wae ~]# yum install gcc
[root@wae ~]# yum install openssl-devel

2. Install python 2.7.9

[root@wae ~]# wget http://python.org/ftp/python/2.7.9/Python-2.7.9.tgz
[root@wae ~]# mv Python-2.7.9.tgz /opt/
[root@wae ~]# cd /opt/
[root@wae opt]# tar -xvf Python-2.7.9.tgz 
[root@wae opt]# cd Python-2.7.9
[root@wae Python-2.7.9]# ./configure --prefix=/usr/local/python2.7
[root@wae Python-2.7.9]# make
[root@wae Python-2.7.9]# make install

完整阅读

Do action by EEM+TCL after the log happen X Times in Y LC/RSP at ASR9k

Problem:

We can do more automated action by EEM + TCL on Cisco router, and have more trigger way for syslog pattern trigger, OID trigger, CPU Threshold trigger and so on. That will match IOS platform, no any issue. But in XR platform, each LC/RSP have separate alarm, we maybe have special requirement, e.g:

Some alarms frequency happen, I want to restart the process (base on pid) if the alarm happen 3 times in 5min on each LC, how to do that?

0/3/cpu0: alarm report "C", Pid = zzz
0/1/cpu0: alarm report "A", Pid = xxx
0/2/cpu0: alarm report "B", pid = yyy
0/3/cpu0: alarm report "C", pid = zzz
0/1/cpu0: alarm report "A", pid = xxx
0/1/cpu0: alarm report "A", pid = xxx

Solution:

We can do interactive script by TCL I/O, create a file in Harddisk/disk which has the history/count of syslog for Lcs. We can read this file using the script whenever the syslog is observed. Based on the number of syslogs the script can take the required action.

The steps will be like this, please check attachment and script flow chart for detail script, in my example, I only dump arp process for testing, please change script base on your requirement, in order to test script, you can add flag to test that, e.g “action_syslog priority info msg “a””: 完整阅读

JAVA FileInputStream 和 FileReader的区别

在写检索文件的函数时,发现读取文件有两种方式,一种是FileInputStream,另一种是FileReader。它们的本质区别就是FileReader读取的是字符数据,而FileInputStream读取的是字节数据,举个简单的例子就知道了,另外下面两篇文章讲这个不错,详细可以点进去看:

java读取文件
Java FileInputStream与FileReader的区别
[Java]读取文件方法大全

package pkg;

import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;

public class ReadFile {
    public static void main(String args[]) {
 
        // 例1 – 使用FileInputStream 读取文件内容
        try (FileInputStream fis = new FileInputStream("test.log")) {
            int da = fis.read(); //读取流中的第一个字节数据
            while (da != -1) { //未到达流的末尾
                System.out.print(Integer.toHexString(da)+" ");
                da = fis.read(); //读取第二个字节数据
            }
            System.out.println();
        } catch (IOException e) {
            System.out.println("Failed to read binary data from File");
            e.printStackTrace();
        }
 
        // 例2 – Java中使用FileReader 读取文件数据
        try (FileReader reader = new FileReader("test.log")) {
            int ch = reader.read();
            while (ch != -1) {
                System.out.print((char) ch);
                ch = reader.read();
            }
        } catch (IOException io) {
            System.out.println("Failed to read character data from File");
            io.printStackTrace();
        }
    }
}

输出结果:

ef bb bf 68 65 6c 6c 6f 21 
hello!

JAVA Jung2 drawing network topology

看到同事用Python写了一个画topology的脚本,感觉很有意思,如果优化下,功能会更实用。最近在看java,是否java也有很好的API可以用?有了这种想法就来Google下吧,在Stackoverflow上发现了两篇需求差不多的文章:
How to dynamically display a simulated network topology in Java
comparing open source java graph drawing frameworks(JUNG and Prefuse) for drawing network topology

上面提到了几个不错的API,JUNG,Prefuse和JGraphX,这偏文章只总结JUNG。关于JUNG的包可以通过下面官网下载:http://jung.sourceforge.net

最新的版本也是5年前的版本了:JUNG 2.0.1,下载下来后是一个zip包,里面包含所有相关的JAR文件,解压后放好,可以随时调用,下面是介绍如何通过Eclipse调用JUNG2:
完整阅读

Eclipse install WindowBuilder pro

WindowBuilder pro是Eclipse可视化制作JAVA UI的插件,如何安装此插件呢?网上留的地址都是Google的地址,很多都不能用了,所以简单在此处说明下,直接去Eclipse官网:
http://eclipse.org/windowbuilder/download.php

找到对应的Eclipse版本,我的是4.3
java-eclipse-windowbuilder-01

在Eclipse点击“Install New Software”,把这个link放进去然后取个名字,就可以安装了,如图:
完整阅读