| 1 | package Plagger::Plugin::Notify::NetSend; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | use base qw(Plagger::Plugin); | ||
| 5 | |||
| 6 | use Encode; | ||
| 7 | use Net::NetSend; | ||
| 8 | |||
| 9 | sub register { | ||
| 10 | my ($self, $context) = @_; | ||
| 11 | $context->register_hook( | ||
| 12 | $self, | ||
| 13 | 'publish.feed' => \&update, | ||
| 14 | ); | ||
| 15 | } | ||
| 16 | |||
| 17 | sub update { | ||
| 18 | my ($self, $context, $args) = @_; | ||
| 19 | my $target_netbios_name = $self->conf->{target_netbios_name}; | ||
| 20 | $target_netbios_name ||= Net::NetSend::getNbName($self->conf->{target_ip}); | ||
| 21 | unless ($target_netbios_name) { | ||
| 22 | $context->log(error => "No netbios name found: $@"); | ||
| 23 | return; | ||
| 24 | } | ||
| 25 | my $body = $self->templatize($context, $args->{feed}); | ||
| 26 | my $success = Net::NetSend::sendMsg( | ||
| 27 | $target_netbios_name, | ||
| 28 | $self->conf->{source_netbios_name}, | ||
| 29 | $self->conf->{target_ip}, | ||
| 30 | encode('shift-jis', $body), | ||
| 31 | ); | ||
| 32 | $context->log(error => "Error in delivery! \n$@") unless $success; | ||
| 33 | } | ||
| 34 | |||
| 35 | sub templatize { | ||
| 36 | my ($self, $context, $feed) = @_; | ||
| 37 | my $tt = $context->template(); | ||
| 38 | $tt->process('net_send_notify.tt', { | ||
| 39 | feed => $feed, | ||
| 40 | }, \my $out) or $context->error($tt->error); | ||
| 41 | $out; | ||
| 42 | } | ||
| 43 | |||
| 44 | 1; | ||
| 45 | __END__ |