Tuesday, November 11, 2014

Utilizing an Android Phone and ADB for paging

I have long used a cellphone connected via USB to our network management system (running Nagios) for page/text/sms'ing, but we recently got a notice from ATT that our ancient Samsung 2G phone was no longer going to be supported. We originally used some software called gnokii for this purpose, but over time moved to gammu (I believe we had originally been using a Nokia phone for this purpose).

Looking at the current state of those two pieces of software, Gammu has been updated more recently but it's author has stated he will not support Android. The pickings are pretty thin, and it is difficult to get to the bottom of if your non-Android/Non-Apple phone will be supported under the software and your provider. So I explored another option, and that ended up being Android and ADB.

For initial testing, I plugged my HTC One M8 into my desktop Ubuntu 14.04 Linux box and started testing. This required me to turn on USB Debugging on my phone and to install the android-tools-adb package. There are many blogs that cover how to do this, my only advice is don't bother with the SDK steps if this is all you are doing. I found Innokenty Sokolov's blog entry about sending sms via adb shell from bash and used that as the initial basis of my work.

After the initial proof of concept, we talked to AT&T about our eligible free upgrades and went with the HTC Desire 610.

I eventually expanded that script to deal with screen blanking, ICS+ changes in screen blanking activity, and added locking with retries. And it eventually ended up something like:

#!/bin/bash
# Initial work from http://qbbr.io/blog/send-sms-via-adb-shell-from-bash.html
# using: ./sendsms.sh 89999999999 "Hello, im SMS from bash"
#

lockfile-create --use-pid --retry 5 /tmp/sendsms


ADB=/usr/bin/adb
# KEYCODE_POWER
$ADB shell input keyevent 26
# KEYCODE_HOME
$ADB shell input keyevent 3
# open form and fill them
$ADB shell am start -a android.intent.action.SENDTO -d sms:$1 --es sms_body "$2" --ez exit_on_sent true
# sleep 1 sec
sleep 1
# KEYCODE_DPAD_RIGHT
$ADB shell input keyevent 22
# KEYCODE_ENTER
$ADB shell input keyevent 66
# KEYCODE_POWER
$ADB shell input keyevent 26
This seems to be working fairly reliably, and allows our NMS system to stack a sufficient number of texts, though it doesn't have quite the elegance of Gammu's queueing, it is getting the job done.

Monday, May 12, 2014

Puppet and Virtual User Creation

I have been using Puppet for more and more admin tasks, and expanding the complexity of what I am doing. Currently, I am doing just about everything in the puppet config files, but am planning on starting to use ENC (initially through Puppet Dashboard, possibly moving to The Foreman). I didn't love the way I was managing users with Puppet, and am in the process of revamping it. I had really needed to virtualize user creation, so that things became manageable. To that end, I found Scott Lowe's Blog on Puppet Account Management, which got me 90% of where I wanted to go. The trick I still wanted to perform was to set an initial password, but not to reset their password after they change it. I had an idea of how to do this using Subscribe, and that at least seems to be working well initially.
define intusers::virtual ($uid,$realname,$pass) {

  user { $title:
    ensure            =>  'present',
    uid               =>  $uid,
    gid               =>  $title,
    shell             =>  '/bin/bash',
    home              =>  "/home/${title}",
    comment           =>  $realname,
#    password          =>  $pass,
    password_max_age => '90',
    password_min_age => '0',
    groups     => ['sudo'],
    managehome        =>  true,
    require           =>  Group[$title],
  }
  group { $title:
    gid               =>  $uid,
  }

  exec { "/usr/sbin/usermod -p \'$pass\' $title":
    refreshonly => true,
    subscribe => User[$title],
    #    logoutput => true,
  }

Tuesday, April 1, 2014

SMART On Windows

I have long been annoyed by the lack of SMART monitoring available for Windows, and when I had previously looked into this the tools that I found were not terribly good. It seems this has been rectified by the Smartmontools Project, which now compiles and functions under Windows. Orsiris de Jong has done one better, and wrapped some other tools and a better installer along with Smartmontools, configuring smartd to start as a service, adding notifications, etc. His project page is at Netpower.fr/smartmontools.