From ae64eccd3fe35bc7d88e50bed9fdc3973c7205bc Mon Sep 17 00:00:00 2001 From: thomas Date: Fri, 16 Feb 2018 16:39:26 +0100 Subject: [PATCH] kvm_monitor: initial commit --- kvm_monitor/51-raritan-kvm.rules | 1 + kvm_monitor/kvm_monitor.pl | 95 ++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100644 kvm_monitor/51-raritan-kvm.rules create mode 100755 kvm_monitor/kvm_monitor.pl diff --git a/kvm_monitor/51-raritan-kvm.rules b/kvm_monitor/51-raritan-kvm.rules new file mode 100644 index 00000000..ac87cd35 --- /dev/null +++ b/kvm_monitor/51-raritan-kvm.rules @@ -0,0 +1 @@ +SUBSYSTEM=="usb", ENV{ID_VENDOR_ID}=="14dd", ENV{ID_MODEL_ID}=="0002", PROGRAM="/lib/udev/kvm_monitor.pl" diff --git a/kvm_monitor/kvm_monitor.pl b/kvm_monitor/kvm_monitor.pl new file mode 100755 index 00000000..aa1c93ef --- /dev/null +++ b/kvm_monitor/kvm_monitor.pl @@ -0,0 +1,95 @@ +#!/usr/bin/perl -w + +use strict; +# use Data::Dumper; $Data::Dumper::Sortkeys=1; +# print Dumper \%ENV + +use constant VERSION => '0.92'; + +# Howto get the id from an attached KVM: +# root> lsusb -v | grep iSerial +# +# Only the first 16 chars are used to identify the KVM, +# the other half is a bit bogous on certain kvm's (ie kvm06). +my %serial_to_name = qw( + 960f2408004ca12a kvm03 + 96132408034ca1d2 kvm04 + 96112408034ca1d6 kvm05 + 960d2408004ca12e kvm06 + 96132408004ca11e kvm07 + 96014404032675fa kvm08 + 96132408004ca132 kvm09 + 96fec24603c408f4 kvm10 + 9600c24600c40814 kvm11 + 960dc24600c47d20 kvm12 + 960dc24600c47d28 kvm13 + 96fec24600c40808 kvm14 + 96fac24603c46bfc kvm15 + 96fec24603c408c8 kvm16 + 96fbc24600c4a740 kvm17 + 96fcc24603c4a7fc kvm18 + 96fcc24603c4a7ec kvm19 +); + +my $action = $ENV{ACTION} || 'missing action'; +my $id = 'missing environment variable'; +if (defined $ENV{ID_SERIAL_SHORT}) { + $id = substr $ENV{ID_SERIAL_SHORT}, 0, 16; +} + +my $name = sprintf "Unknown KVM with ID '%s'", $id; +$name = $serial_to_name{$id} if exists $serial_to_name{$id}; + +my $msg = 'kvm-event: ' . $name; +if ($action eq 'add') { + $msg .= ' was attached.'; +} elsif ($action eq 'remove') { + $msg .= ' was removed.'; +} else { + $msg .= ", and an unknown event has occurred ($action)"; +} + +system('/usr/bin/logger', $msg); + +exit; + +=head2 + + The environment seen (kvm13) + +ACTION=add +ACTION=remove + + ==== event ==== +Thu May 26 13:08:33 CEST 2016 +ACTION=add +BUSNUM=002 +DEVLINKS=/dev/char/189:136 +DEVNAME=bus/usb/002/009 +DEVNUM=009 +DEVPATH=/devices/pci0000:00/0000:00:1d.0/usb2/2-1/2-1.3 +DEVTYPE=usb_device +ID_BUS=usb +ID_MODEL=Multidevice +ID_MODEL_ENC=Multidevice +ID_MODEL_ID=0002 +ID_REVISION=0001 +ID_SERIAL=Peppercon_AG_Multidevice_960dc24600c47d282641C894DA0F1B6A +ID_SERIAL_SHORT=960dc24600c47d282641C894DA0F1B6A +ID_USB_INTERFACES=:030101:030102: +ID_VENDOR=Peppercon_AG +ID_VENDOR_ENC=Peppercon\x20AG +ID_VENDOR_ID=14dd +MAJOR=189 +MINOR=136 +PRODUCT=14dd/2/1 +PWD=/ +SEQNUM=3362 +SHLVL=1 +SUBSYSTEM=usb +TYPE=0/0/0 +UDEV_LOG=3 +_=/usr/bin/env + +=cut +