Possible project
- At least, 200x Raspberries in different locations
- We can have two or three Raspberries in the same location.
- Firewall in all locations
- No starting date known
- Instalallation from the same image so the hostname is the same in all of them.
- Nobody can log in
Question
Key
Workflow
In zabbix-agent:
- Configure agent as active, disable passive (firewall installed, do you remember it?)
- I need to create a random hostname but i need to identify each Raspberry in the same/different locations. So i created this python script to get a hostname (i chose publicip-macaddress name):
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import fcntl, socket, struct, urllib2 | |
def getHwAddr(ifname): | |
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) | |
info = fcntl.ioctl(s.fileno(), 0x8927, struct.pack('256s', ifname[:15])) | |
return '_'.join(['%02x' % ord(char) for char in info[18:24]]) | |
def getPublicAddr(): | |
r = urllib2.urlopen("http://ipinfo.io/ip") | |
ip = r.read(100) | |
return ip[:-1] | |
print getPublicAddr() + "-" + getHwAddr('eth0') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
root@raspberry:~# /usr/local/bin/get_macname.py | |
84.126.70.xx-b8_xx_eb_a4_xx_xc |
In the agent config you will need to run this script, two keys here:
EnableRemoteCommands=1
HostnameItem=system.run["/usr/local/bin/get_macname.py"]
You will need to put a Meta for the autoregister:
HostMetadata=RaspberryColThe agent is ready.
For the server you will need to clone a OS Linux template to convert it as Active. You will need to change the Type item by item in the cloned template:
Now the new autoregistration rule.
That's all.