summaryrefslogtreecommitdiff
path: root/notify-printer-status
blob: 08ff01ccd7b7cd053c7a44a9df373743070744e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env perl
# vim:ts=4:sw=4:expandtab
# © 2012 Michael Stapelberg (see LICENSE)
# depends on Net::SNMP and Desktop::Notify
# sudo apt-get install libnet-snmp-perl libdesktop-notify-perl

use strict;
use warnings;
use Net::SNMP qw(snmp_type_ntop);
use Desktop::Notify;
use v5.10;

my $notify = Desktop::Notify->new();

my ($snmp, $error) = Net::SNMP->session(
    -hostname => 'kyocera.rag.lan',
);

die "SNMP init error: $error" unless defined($snmp);

my $last_status = '';
while (1) {
    # The OID means "prtConsoleDisplayBufferText"
    my $reply = $snmp->get_request(-varbindlist => [
        '1.3.6.1.2.1.43.16.5.1.2.1.1'
    ]);
    die $snmp->error() unless defined($reply);

    for ($snmp->var_bind_names()) {
        my $status = $snmp->var_bind_list()->{$_};
        if ($status ne $last_status) {
            if ($status ne 'Ruhemodus') {
                my $notification = $notify->create(
                    summary => 'kyocera status:',
                    body => $status,
                    timeout => 5000
                );
                $notification->show();
            }
            $last_status = $status;
        }
    }
    sleep 1;
}