When work moved to it’s temporary home during construction, we were forced to move one of our labs to the campus library, into a room that was, not exactly lab-worthy. It’s totally enclosed, and poorly air conditioned. During fall term, the students and faculty that were in that space complained about the heat, and we worked with the library to help address it.
But, new term, and new students/faculty bring new complaints. Problem is, we didn’t really have a good grasp on the temperature in there. So, today I set about fixing that.
There are really 3 things needed to get this working.
- Copy of tempmonitor (found here, in /Volumes/Temperature\ Monitor\ 4.94/TemperatureMonitor.app/Contents/MacOS/)
- snmpd.conf (will show REAL basic one below)
- Script to grab temp, and report it
Really, all of this is pretty darn simple. So, here we go.
Take tempmonitor, and drop it somewhere like /usr/local/bin/, or if you’re lazy, /usr/bin/. This will let you easily say “tempmonitor” at the CLI, and get back your temps for the computer.
Then, edit your snmpd.conf with something like: sudo nano -w /etc/snmp/snmpd.conf and put in something like:
rocommunity public 10.0.0.0/24
extend ambient_temp /usr/local/bin/checktemp.sh
Note the subnet specified. That’s who is allowed to access the snmp info. I would recommend setting that, so you aren’t getting hit by random people running snmpwalk.
Last part is creating the “checktemp.sh” script. Just do something like “sudo nano -w /usr/local/bin/checktemp.sh” and put in something like:
#!/bin/bash
t=`/usr/local/bin/tempmonitor -a -l -f | grep AMBIENT | cut -d" " -f4 | bc | awk '{printf "%.0f\n", $1}'`
exit $t
For the keen eyed, yes, I’m exiting with a non-zero. This is how you force snmp to pass an integer back, rather than a string. This took me a bit to figure out.
So, with all that in place, you should be able to do “sudo launchctl load -w /System/Library/LaunchDaemons/org.net-snmp.snmpd.plist” to load up snmp. On another computer, assuming it’s in the subnet you specified in the snmpd.conf, you should be able to do “snmpwalk -On -cpublic -v2c -m “+/usr/share/snmp/mibs/NET-SNMP-EXTEND-MIB.txt” aaa.bbb.ccc.ddd nsExtendObjects” where aaa.bbb.ccc.ddd is the IP address of the computer, and bam, you should get back several things, one of which will be the current rounded ambient air temp of the computer in question (assuming it has an ambient air sensor). I’m still trying to figure out how to pass back a float, which would allow a decimal point number. The other option would be to multiply the output by 10, then have your snmp app divide it by 10 to get your decimal. *shrugs* up to you.
Good luck!