2014/01/21

postfix如果要利用header_checks來check中文是會有問題的
必須先把中文進行編碼
網址如下
http://www.mytju.com/classCode/tools/base64.asp
要分utf8或big5

編出來之後再加入header_checks
/^Subject:.*5biQ5oi3/ DISCARD
/^Subject:.*pc6k4Q==/ DISCARD

postfix要重啟

2014/01/16

Gluster 系統服務
啟動Gluster服務:
指令:
service glusterfs-server start

停止Gluster服務:
指令:
service glusterfs-server stop

檢視Gluster服務:
指令:
service glusterfs-server status

Gluster 節點指令
檢視Gluster 節點狀態:
指令:
gluster peer status

新增Gluster 節點:
指令:
gluster peer probe <HOSTNAME>
說明:
HOSTNAME為您要新增該節點的主機名稱

刪除Gluster 節點:
指令:
gluster peer detach <HOSTNAME>
說明:
HOSTNAME為您要刪除該節點的主機名稱

Gluster 卷冊指令
檢視Gluster 卷冊狀態:
指令:
gluster volume info

新增分散式卷冊(Distributed Volumes):
指令:
gluster volume create <NEWVOLUMENAME> [transport [tcp | rdma | tcp,rdma]] <NEWBRICK1> <NEWBRICK2>...
說明:
1.NEWVOLUMENAME為您要新增的卷冊名稱
2.transport為傳輸模式,預設不輸入該指令參數是使用tcp模式
3.NEWBRICK為您要新增至卷冊之節點儲存區塊

新增複製式卷冊(Replicated Volumes):
指令:
gluster volume create <NEWVOLUMENAME> [replica COUNT] [transport [tcp |rdma | tcp,rdma]]<NEWBRICK1> <NEWBRICK2>...
說明:
1.NEWVOLUMENAME為您要新增的卷冊名稱
2.replica COUNT為副本的數量
3.transport為傳輸模式,預設不輸入該指令參數是使用tcp模式
4.NEWBRICK為您要新增至卷冊之節點儲存區塊

新增帶狀式卷冊(Striped Volumes):
指令:
gluster volume create <NEWVOLUMENAME> [stripe COUNT] [transport [tcp | rdma | tcp,rdma]]<NEWBRICK1> <NEWBRICK2>...
說明:
1.NEWVOLUMENAME為您要新增的卷冊名稱
2.stripe COUNT為帶狀的數量
3.transport為傳輸模式,預設不輸入該指令參數是使用tcp模式
4.NEWBRICK為您要新增至卷冊之節點儲存區塊

新增分散複製式卷冊(Distributed Replicated Volumes):
指令:
gluster volume create <NEWVOLUMENAME> [replica COUNT] [transport [tcp | rdma | tcp,rdma]]<NEWBRICK1> <NEWBRICK2>...
說明:
1.NEWVOLUMENAME為您要新增的卷冊名稱
2.replica COUNT為副本的數量
3.transport為傳輸模式,預設不輸入該指令參數是使用tcp模式
4.NEWBRICK為您要新增至卷冊之節點儲存區塊

增加儲存區塊(Brick)至現有卷冊中:
指令:
gluster volume add-brick <VOLUMENAME> <NEWBRICK>
說明:
1.VOLUMENAME為您要加入儲存區塊的卷冊名稱
2.NEWBRICK為您要新增至卷冊之節點儲存區塊

移除儲存區塊(Brick)於現有卷冊中:
指令:
gluster volume remove-brick <VOLUMENAME> <BRICK> start
說明:
1.VOLUMENAME為您要移除儲存區塊的卷冊名稱
2.BRICK為您要移除儲存區塊名稱

檢視移除儲存區塊(Brick)狀態:
指令:
gluster volume remove-brick VOLUMENAME BRICK status
說明:
1.VOLUMENAME為您所移除儲存區塊的卷冊名稱
2.BRICK為您要移除儲存區塊名稱

提交移除儲存區塊(Brick)狀態:
指令:
gluster volume remove-brick VOLNAME BRICK commit
說明:
1.VOLUMENAME為您所移除儲存區塊的卷冊名稱
2.BRICK為您要移除儲存區塊名稱

啟用卷冊:
指令:
gluster volume start <VOLUMENAME>
說明:
VOLUMENAME為要啟用的卷冊名稱

停用卷冊:
指令:
gluster volume stop <VOLUMENAME>
說明:
VOLUMENAME為要停用的卷冊名稱

刪除卷冊:
指令:
gluster volume delete <VOLUMENAME>
說明:
1.VOLUMENAME為要刪除的卷冊名稱
2.要刪除卷冊之前必須要先停用卷冊

掛載卷冊
手動掛載卷冊:
指令:
mount.glusterfs HOSTNAME-OR-IPADDRESS:/VOLUMENAME MOUNTDIR
說明:
1.HOSTNAME-OR-IPADDRESS為您所要掛載的主機名稱或IP及掛載的卷冊名稱
2.MOUNTDIR為您所要掛載的目的地路徑
參考資料:http://www.gluster.org

http://ithelp.ithome.com.tw/question/10107251

2014/01/07

python 從2.4開始建議使用
subprocess來取代

os.system
os.spawn*
os.popen*
popen2.*
commands.*

除了 subprocess.call() 之外,另外還有 check_call() 跟 check_output()。

除了 check_output 會回傳 output 之外,用法相同跟 call() 一樣。只不過會自動檢查 return code,如果是非零值的話,就會直接丟出 CalledProcessError,這個時候 return code 還是可以透過 returncode 這個 attribute 來取回。例如:(但是要執行的程式不存在時,還是會丟出 OSError)

如果要捉取回傳的值來進行某些判斷的話
就要使用subprocess.check_output()
範例如下

import subprocess

a = subprocess.check_output("dir", shell=True)
print a

b = a.find('zz')
print b


http://docs.python.org/2/library/subprocess.html
http://imsardine.wordpress.com/tech/shell-scripting-in-python/

2014/01/05

import telnetlib

f = open("switch")
lines = f.read().splitlines()
#print lines
command_arr = ["123456","en","123456","terminal length 0","sh mac add","exit"]
#print command_arr

for HOST in lines:
#print HOST
tn = telnetlib.Telnet(HOST)
for command in command_arr :
        tn.write(command + "\n")
#print tn.read_all()
content = tn.read_all()
print content
chk = content.find("1122.3344.5566") #找出這個mac是否在這台switch上 在那一個port上
print chk
tn.close()

python 讀檔

f = open("1")
lines = f.read().splitlines()
 #如果不用spllitlines則會把分行符號\n一起放到list去

print lines
#列出lines這個list的所有示素

for i in lines:
print i
#分行列出list裡的所有元素

結果如下
['afdkfj', 'fsldfjk', 'fjslfk', 'fsdlkfj', 'fsldfj']
afdkfj
fsldfjk
fjslfk
fsdlkfj
fsldfj

2014/01/04

使用python的 telnetlib對網路設備進行一些自動化的操作
範例如下


import telnetlib

HOST = "1.1.1.1"

tn = telnetlib.Telnet(HOST)

tn.read_until("Password: ")
tn.write("12345\n")
tn.read_until("cc>")
tn.write("en\n")
tn.read_until("Password: ")
tn.write("12345\n")

tn.write("sh flash\n")
tn.write("exit\n")
print tn.read_all()

http://blog.johnsonlu.org/category/programe/pythin/
http://docs.python.org/2/library/telnetlib.html

2014/01/01

最近碰到一個很奇怪的問題
使用了一段時間的aruba ap
突然發生無法使用的情況
查了一下brocade icx 6450的log發現是ap向switch要更多的電
原本是使用802.3 af的 15400ma
但switch無法提供更多
因此視為異常而把port disable了
但該ap並不是新裝而是已經使用一段時間了
搞不清楚到底是ap還是switch 的問題
因為有二顆出現這個情況
所以先送修一個回aruba原廠
同時詢問brocade原廠
大約隔了二週
 brocade給了一個針對poe module的patch
上上去之後
目前看起來是正常
更新指令如下

 inline power install-firmware [stack-unit |unit-number] tftp ip-address filename

必須先用show run看poe是在那一個unit
今天稍微玩了一下lxc

如果只用linux是可以考慮的選擇
但支援的linux也不多
目前支援的如下圖

有web介面可以管理
如下連結
http://lxc-webpanel.github.io/index.html

web介面安裝指令
wget http://lxc-webpanel.github.io/tools/install.sh -O - | bash

但要進入guest的console還是要下指令

相關指令如下
lxc-create  -n  虛擬機器名稱  -t  ubuntu

lxc-console -n 虛擬機器名稱

sudo lxc-shutdown  -n 虛擬機器名稱

如果不熟linux的應該會不太適應

不過效能上應該是比較好的
測試的環境是先在virtualbox上裝ubuntu
之後才在ubuntu上裝lxc
guest中的guest
沒有什麼lag

http://www.arthurtoday.com/2012/10/ubuntu-create-and-setting-lxc-containers.html#.UsOuPtIW2So

2013/12/22

borcade

http://www.brocade.com/downloads/documents/product_manuals/MIB/IPMIB_Reference_Jun2013.pdf

OID前要加上 1.3.6.1.4.1.1991

1.3.6.1.4.1.1991.1.1.1.1.18  机器溫度

cisco 溫度相關oid

iso.3.6.1.4.1.9.9.13.1.3.1.2.1005 = STRING: "SW#1, Sensor#1, GREEN "
iso.3.6.1.4.1.9.9.13.1.3.1.2.2005 = STRING: "SW#2, Sensor#1, GREEN "
iso.3.6.1.4.1.9.9.13.1.3.1.3.1005 = Gauge32: 30
iso.3.6.1.4.1.9.9.13.1.3.1.3.2005 = Gauge32: 33
iso.3.6.1.4.1.9.9.13.1.3.1.4.1005 = INTEGER: 65
iso.3.6.1.4.1.9.9.13.1.3.1.4.2005 = INTEGER: 65
iso.3.6.1.4.1.9.9.13.1.3.1.5.1005 = INTEGER: 0
iso.3.6.1.4.1.9.9.13.1.3.1.5.2005 = INTEGER: 0
iso.3.6.1.4.1.9.9.13.1.3.1.6.1005 = INTEGER: 1
iso.3.6.1.4.1.9.9.13.1.3.1.6.2005 = INTEGER: 1

以下為目前實際值
.1.3.6.1.4.1.9.9.13.1.3.1.3.1005

舊型机器(2U)不支援此OID

2013/12/19

最近在進行Arcsight的POC

整理了一下search 語法

fortigate virus | top destinationAddress

fortigate Malicious | top destinationAddress

fortigate ips AND (sourceAddress IS NOT NULL) | top sourceAddress

fortigate spam | top sourceAddress

2013/12/16

之前在尋找cacti上的告警机制的時候有找到thold這個模組可以來設定
但因不太想用plugin而作罷
最近想到應該可以直接撈rrd file的值來用
就可以寫個shell來處理了

原始rrdtool撈出來的結果如下

rrdtool fetch 123.rrd AVERAGE --start -300
                       
                             123              

1387170000: 4.2220000000e+03
1387170300: -nan

但因為這樣不好判斷 查了一下轉成十進位的方法
指令如下
printf "%f\n" `rrdtool fetch 123.rrd AVERAGE --start -300|grep e+|cut -d ' ' -f 2`
得出的結果就會是
4222
以方便程式的判斷

2013/12/11

取得設備的OID之後要在cacti上畫圖的方法如下

先增加一個
Data Templates

在設定Data Templates時
Associated RRA's  的第一個選項 Hourly一定要取消(預設是全選的)
否則會造成圖畫不出來的問題






之後再依據這個Data Templates加上
Graph Templates
詳細步驟如下連結
http://kb.fortinet.com/kb/viewAttachment.do?attachID=Fortigate%20SNMP%20Graphs%20with%20Cacti.pdf&documentID=13833

但加完後卻發生一個問題就是圖有出來但是沒有資料
看了一下rra file

rrdtool fetch 123.rrd AVERAGE
                  data

1386653400: -nan
1386653700: -nan
1386654000: -nan
1386654300: -nan
1386654600: -nan
1386654900: -nan
1386655200: -nan
1386655500: -nan
1386655800: -nan
1386656100: -nan
1386656400: -nan
1386656700: -nan
1386657000: -nan
1386657300: -nan
1386657600: -nan

完全沒有收到資料
可是用snmpwalk去撈是有資料啊

再仔細看了一下上面的文件
發現了一句話

snmpwalk -v 2c -c public 10.69.69.1 .1.3.6.1.4.1.12356.17.102.3.1.2
SNMPv2-SMI::enterprises.12356.17.102.3.1.2.1 = Counter32: 1229

Notice that the snmpwalk came back with an OID of 12356.17.102.3.1.2.1 The extra trailing ‘.1’ would be 
the OID that should be put into the Data Template Custom Data section. 

snmpwalk撈出來是有值沒錯
但在Data Template必須在最OID的最後再加上.1

之後如果再發生類似的情況 snmpwalk有值卻畫不出來
把OID最後再加上.0或.1試看看
原則上再加上去smnpwalk也還是能撈出值而且值跟沒加時相同
同時cacti也會正常
終於解開了長久以來的疑惑




近來發現很多設備出現無跟ntp server校時的問題
到ntp server上查看 ntpstat
出現unsynchronised
但ntpq -p
是正常
不知道是不是跟ipv6上線有關
因為之前都沒發生這個問題
先把ntp server的ipv6關了
再改了一下ntp.conf
觀察看看

修改部分如下

把ipv6部分的config mark

#restrict -6 default kod nomodify notrap nopeer noquery
#restrict -6 ::1

restrict 127.0.0.1
restrict default nomodify

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server  127.127.1.0     # local clock
fudge   127.127.1.0 stratum 10

2013/12/09

參考了以下的文章
把fortiget的相關monitor加到cacti
但session那個oid有問題





在設定Data Templates時
Associated RRA's  的第一個選項 Hourly一定要取消(預設是全選的)
否則會造成圖畫不出來的問題


http://www.paulscomputerservice.net/articles/article.php?ID=211
http://kb.fortinet.com/kb/viewAttachment.do?attachID=Fortigate%20SNMP%20Graphs%20with%20Cacti.pdf&documentID=13833
http://www.netadmin.com.tw/article_content.aspx?sn=1301020001

2013/12/07

原本在snort設定的portscan偵測看起來發揮了不少作用
今天再加上特徵值的偵測阻擋
目前門檻值先設為100
即某個ip觸犯snort的rule到達100次後便加以封鎖
先醬觀察看看
程式碼如下

#!/usr/bin/python

import MySQLdb

db = MySQLdb.connect(host="localhost", user="root", passwd="abcd1234", db="snort")
cursor = db.cursor()

cursor.execute("select count(*) as cnt,inet_ntoa(ip_src) from event,iphdr where event.cid=iphdr.cid and event.sid=iphdr.sid and DATE(event.timestamp) = CURDATE() group by ip_src order by cnt")
result = cursor.fetchall()
#fetch select result to list

if result:
        for record in result:
                if record[0]>100:
                #set malice count 100
                        print record[1]
db.close()

select signature,count(*) as cnt,inet_ntoa(ip_src) from event,iphdr where event.cid=iphdr.cid and event.sid=iphdr.sid group by ip_src order by cnt;

Good!
http://sgros.blogspot.tw/2012/07/querying-snort-sql-database.html

2013/11/27

當使用程式在windows去呼叫指令的時候
如果沒有特別指定
一律會使用32bit的方式來跑
http://evenrain.com/32-bit-python-get-problem-in-x64-windows/

為了解決python在64bit OS上的問題
程式作了如下的修正

if os.path.isdir('c:\Program Files (x86)'): #判斷OS的版本
           p = subprocess.Popen( r'c:\windows\sysnative\wscript.exe c:\windows\system32\slmgr.vbs -skms 10.1.1.1:1688' )
            p.wait()
            p = subprocess.Popen( r'c:\windows\sysnative\wscript.exe c:\windows\system32\slmgr.vbs -ato' )
            p.wait()
           
解決了kms認証時會出現奇怪錯誤的問題
感謝 seek steve 的幫忙          

2013/11/26

windows清除kms key的方法

slmgr -ckms
slmgr -rearm