Friday, May 15, 2009

EC2 instance meta-data via SNMP

Here is a simple script and a sample snmp.conf file which will enable you to query your EC2 instance meta-data via SNMP. For more information on meta-data, see (see page 49 EC2 Developers Guide ).

# This script returns metadata specific to AWS instances
# See Page 49, Amazon Elastic Compute Cloud - Developer Guide

from httplib import HTTPConnection
from sys import argv
import socket

if len(argv) > 1:
conn = HTTPConnection("")
url = "/latest/meta-data/" + str(argv[1])
r1 = conn.getresponse()
if r1.status == 200:
print r1.status,url
except socket.error,msg:
print msg[1]
print "data key missing"


rwcommunity EDF9ErIfzNFb
rocommunity public

syslocation AWS

com2sec notConfigUser default public
group notConfigGroup v1 notConfigUser
group notConfigGroup v2c notConfigUser

view systemview included .
view systemview included .

view systemview included . view systemview included .

view systemview included .

access notConfigGroup "" any noauth exact systemview none none

# Added for support of bcm5820 cards.
pass . /usr/bin/ucd5820stat


# Executable Scripts
# AWS Specific
exec ami-id /etc/snmp/ ami-id
exec ami-launch-index /etc/snmp/ ami-launch-index
exec ami-manifest-path /etc/snmp/ ami-manifest-path
exec ancestor-ami-ids /etc/snmp/ ancestor-ami-ids
exec block-device-mapping /etc/snmp/ block-device-mapping
exec instance-id /etc/snmp/ instance-id
exec instance-type /etc/snmp/ instance-type
exec local-hostname /etc/snmp/ local-hostname
exec local-ipv /etc/snmp/ local-ipv4
exec kernel-id /etc/snmp/ kernel-id
exec availability-zone /etc/snmp/ availability-zone
#exec product-codes /etc/snmp/ product-codes
exec public-hostname /etc/snmp/ public-hostname
exec public-ipv4 /etc/snmp/ public-ipv4
#exec public-keys /etc/snmp/ public-keys
exec ramdisk-id /etc/snmp/ ramdisk-id
exec reservation-id /etc/snmp/ reservation-id
exec security-groups /etc/snmp/ security-groups

# Disk Checks
disk /

# Process Checks
proc crond
proc ntpd
proc rsyslogd
proc sshd

Sample Output

[root@ami1 ~]# snmpwalk -Os -c public -v 2c localhost .
extOutput.1 = STRING: ami-08f41161

[root@ami1 ~]# snmpwalk -Os -c public -v 2c localhost .
extOutput.2 = STRING: 101

Hope this helps!

No comments:

Post a Comment