Run mini_snmpd on OpenWRT

###OpenWRT Configuration Install mini_snmpd:

	$ opkg update
	$ opkg install mini-snmpd

Configure mini_snmpd: mainly changes: option enabled 1, then change the option contact and location. But infact we can only fetch list interfaces in cacti:

	root@OpenWrt:~# cat /etc/config/mini_snmpd 
	config mini_snmpd
		option enabled 1
		option ipv6 0
		option community 'public'
		option contact 'gwoguowug@gmail.com'
		option location 'Asia/China/Nanjing'
	
		# enable basic disk usage statistics on specified mountpoint
		list disks '/jffs'
		list disks '/tmp'
	
		# enable basic network statistics on specified interface
		# 4 interfaces maximum, as named in /etc/config/network
		list interfaces 'loopback'
		list interfaces 'lan'
		list interfaces 'wan'

Restart the mini_snmpd:

	$ /etc/init.d/mini_snmpd restart

###Cacti Configuration Add a new device named OpenWRT, the configuration may like following:

	Change the Host Template to Generic SNMP-enabled Host
	Downed Device Detection - Ping
	Ping Method - ICMP Ping

Then you can add your own data sources, graph templates, new graph, new graph Trees, then display them. the picture may looks like as following:

Alt text

Add optional data into snmpd

###Prepare the script We get the current system load from /proc/loadavg:

	[Trusty@XXXyyy ~]$ cat /bin/online.sh
	#!/bin/sh
	echo .1.3.6.1.4.1.102.8
	cat /proc/loadavg | awk {'print $1'}

Then we have to add this script to our /etc/snmp/snmpd.conf:

	extend .1.3.6.1.4.1.2021.53 online_monitor /bin/sh /bin/online.sh

Restart the service:

	systemctl restart snmpd

Use snmpwalk to view the newly added item:

	snmpwalk -v 2c -c public 10.0.0.221 .1.3.6.1.4.1.2021.53

###Fetch the data See the following data is what we want:

	root@ubuntu:/etc# snmpwalk -v 2c -c public 10.0.0.221 .1.3.6.1.4.1.2021.53.4.1.2.14.111.110.108.105.110.101.95.109.111.110.105.116.111.114.2
	iso.3.6.1.4.1.2021.53.4.1.2.14.111.110.108.105.110.101.95.109.111.110.105.116.111.114.2 = STRING: "0.77"

###Draw images in cacti First, add a data templates:
Console->Data Templates->Add,
Data Template Name: MonitorArchCustomized
Data Source Name: |host_description|-MonitorArchCustomized
Data Input Method: Get SNMP Data
Associated RRA’s: Hourly(1 Minutes Average)
Internal Data Source Name: MonitorArchCustom
Then click “Create”
some additional field will be displayed, in the newly field “Custom Data [data input: Get SNMP Data]” insert the OID field with “.1.3.6.1.4.1.2021.53.4.1.2.14.111.110.108.105.110.101.95.109.111.110.105.116.111.114.1”(which you got from the snmpwalk output result)

Second, add a graph templates:
Templat Name: MonitorArchCustomized
Graph template Title: |host_description|-MonitorArchCustomized
Create and then insert the Graph Template Items, add like following:

	Graph Item 	Data Source 	Graph Item Type 	CF Type 	Item Color
	Item # 1 	(MonitorArchCustom): 	AREA 	AVERAGE 	  	FF00FF 	Move Down Move Up 	Delete
	Item # 2 	(MonitorArchCustom): 	GPRINT 	LAST 	  	F5F800 	Move Down Move Up 	Delete
	Item # 3 	(MonitorArchCustom): Average 	GPRINT 	AVERAGE 	  	8D85F3 	Move Down Move Up 	Delete
	Item # 4 	(MonitorArchCustom): MAX 	GPRINT 	MAX 	  	005D57 	Move Down Move Up 	Delete

Also notice the Data Source should be MonitorArchCustom.

Third, add a new graph under Host of ArchLinux.
Select the Graph template and then click Create.

After some minutes, you will see the newly captured data and the images under graphs-> Arch-> Host:ArchLinux. Maybe Your graphs trees are not the same as mine, you got found your own location.

cacti_image

Cacti and snmpd

On the machine being monitored, check the snmpd configuration file, you will find some items like following:

	$ cat /etc/snmp/snmpd.conf
	rocommunity public 
	rwcommunity admin
	agentaddress tcp:161
	If you want to enable Location and contact, add:
	syslocation Bat. C2
	syscontact someone@somewhere.org

On the monitor PC, we can use following command to view the monitored machine’s status:

	$ snmpwalk -c Trusty -v 2c 10.0.0.221:661
	or
	$ snmpwalk -c Trusty -v 2c 10.0.0.221

How to configure cacti

Add a new device for monitoring: Console-> Management->Devices, add new, the configuration should like following:

Alt text

After save, you should view the result displayed like:

	ArchLinux (10.0.0.221) 
	 SNMP Information
	System:Linux DashArch 3.11.6-1-ARCH #1 SMP PREEMPT Fri Oct 18 23:22:36 CEST
	 2013 x86_64
	Uptime: 1137 (0 days, 0 hours, 0 minutes)
	Hostname: DashArch
	Location: Unknown
	Contact: root@localhost

Draw disks

Add following line into snmpd.conf

	includeAllDisks

But I failed, later will change. ###Add Graphs Click “Create Graphs for this Host”, then you will asked to add the graphs.
After you add the graphs, add a new graph trees. Then add a Tree Items, Parent -> [root] Tree Item Type –> Host, Host –> ArchLinux(10.0.0.221), then save.
Now click on graphs, you can get your tree and view all of the images.
###Add Device for Winxp Install the snmp service under control pannel.
enable the snmp service in Administration tools -> Service.
In cacti, add a new equipment, host templates choose “Windows 2000/XP host” , Downed Device Detection choose “SNMP uptime” , then add your own data source and graphics.

NetBSD Start

###Installation and Configuration Download the install.iso and install it in the virtualbox.
Then add http_proxy, https_proxy, ftp_proxy, ftps_proxy into the .profile file.
visudo add the current user to the sudo list, then add Defaults env_keep to the http_proxy, etc, because we want to use pkg_add under the sudo priviledge.

###Updating the software repository snapshot Edit the Package path via:

	 export PKG_PATH=ftp://filedump.se.rit.edu/pub/OpenBSD/5.3/`machine -a`/

Update the ports configuration database:

	$ cd /tmp
	$ ftp ftp://filedump.se.rit.edu/pub/OpenBSD/5.3/ports.tar.gz
	$ cd /usr
	$ sudo tar xzf /tmp/ports.tar.gz

Now you got the updated port information.

###Search and install specified packages via ports system Take vim installation for example:

	$ cd /usr/ports
	$ make key=vim describe
	$ make search key=****
	$ cd /usr/ports/editors/vim
	$ sudo make install
	or
	$ sudo make install clean clean-depends

Then the ports will take a long,long time to download all of the packages and start to build. Strangely, this command installed gvim into the system.

My Translator in ArchLinux+Awesome(2)

###Prefix 3 days ago I wrote a simple translator on my ArchLinux which could pop-up a notification window when I query a word. But when I use it at company it failed. Becaus the firewall has banned the communication to Google’s API. Thus I have to write another version of translator, which could get the result from the local database. ###Preparation python-stardict is a great library for querying word from stardict’s dictionary, you can get it via:

	$ git clone https://github.com/pysuxing/python-stardict.git

Also you have to download stardict’s dictionary from http://abloz.com/huzheng/stardict-dic/, you can choose whatever you like dictionary, then uncompress it into your python-stardict located directory. ###Coding Open stardict.py with your favorite editor, adding a function at the end of the file. The code snippet is listed as following:

def my_read_dict_info():
    """
    """
    my_ifo_file = "/home/Trusty/code/python/python-stardict/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.ifo"
    my_idx_file = "/home/Trusty/code/python/python-stardict/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.idx"
    my_dict_file = "/home/Trusty/code/python/python-stardict/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.dict.dz"
    #########Uncomment them for other dictionaries ######
    #my_dict_file = "stardict-dictd_www.dict.org_gcide-2.4.2/dictd_www.dict.org_gcide.dict.dz"
    #my_idx_file = "stardict-dictd_www.dict.org_gcide-2.4.2/dictd_www.dict.org_gcide.idx"
    #my_ifo_file = "stardict-dictd_www.dict.org_gcide-2.4.2/dictd_www.dict.org_gcide.ifo"
    #my_ifo_file = "stardict-longman-2.4.2/longman.ifo"
    #my_idx_file = "stardict-longman-2.4.2/longman.idx"
    #my_dict_file = "stardict-longman-2.4.2/longman.dict.dz"
    my_ifo_reader = IfoFileReader(my_ifo_file)
    my_idx_reader = IdxFileReader(my_idx_file)
    my_dict_reader = DictFileReader(my_dict_file, my_ifo_reader, my_idx_reader, True)
    cmdargs = str(sys.argv) ## args
    result = my_dict_reader.get_dict_by_word(str(sys.argv[1]))  ## Using args[1] for querying
    print result[0].values()[0]		## output result in terminal
    result_str = "\'<span color=\"green\" size=\"14000\">"+result[0].values()[0]+"</span>\'"	## Build the command line for notify-send
    #print result_str
    call(["notify-send", str(sys.argv[1]), result_str])		## Call notify-send to print on screen, last for 5 seconds
    #call(["echo", commandstr])
    #output = subprocess.check_output(["echo", commandstr])
    #p1 = subprocess.Popen(['echo','-e', commandstr], stdout=subprocess.PIPE)
    #p1 = subprocess.Popen(['printf', commandstr], stdout=subprocess.PIPE)
    #p2 = subprocess.Popen(['awesome-client', '-'], stdin=p1.stdout, stdout=subprocess.PIPE)
    #p1.stdout.close()
    #output = p2.communicate()[0]
    #print "*****"
    #print output

# read_ifo_file("stardict-cedict-gb-2.4.2/cedict-gb.ifo")
# read_idx_file("stardict-cedict-gb-2.4.2/cedict-gb.idx")
# read_dict_info()
my_read_dict_info()

Clean code:

def my_read_dict_info():
    """
    """
    my_ifo_file = "/home/Trusty/code/python/python-stardict/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.ifo"
    my_idx_file = "/home/Trusty/code/python/python-stardict/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.idx"
    my_dict_file = "/home/Trusty/code/python/python-stardict/stardict-langdao-ec-gb-2.4.2/langdao-ec-gb.dict.dz"
    my_ifo_reader = IfoFileReader(my_ifo_file)
    my_idx_reader = IdxFileReader(my_idx_file)
    my_dict_reader = DictFileReader(my_dict_file, my_ifo_reader, my_idx_reader, True)
    cmdargs = str(sys.argv) ## args
    result = my_dict_reader.get_dict_by_word(str(sys.argv[1]))  ## Using args[1] for querying
    print result[0].values()[0]		## output result in terminal
    result_str = "\'<span color=\"green\" size=\"14000\">"+result[0].values()[0]+"</span>\'"	## Build the command line for notify-send
    call(["notify-send", str(sys.argv[1]), result_str])		## Call notify-send to print on screen, last for 5 seconds

my_read_dict_info()

###Configuration You can add an alias into your ~/.bashrc

	alias mydict='python2 /home/Trusty/code/python/python-stardict/stardict.py'

Or you can add an executable file named /bin/mydic which contains:

#!/bin/bash
python2 /home/Trusty/code/python/python-stardict/stardict.py $@

###Result See the following images for result:

Alt text
Alt text

The query result will vanished in 5 seconds. ###TBD

  • How to automatically record every query?
  • How to replace the python-stardict with my own library(Written in C, much more fast?)?
  • How to automatically judge english/chinese, or other languages?
  • Considering Error Handling.