From bbe4fd1c1455e92a4aa7b05a165c9b21f2d71d42 Mon Sep 17 00:00:00 2001 From: qgarnier Date: Mon, 1 Feb 2021 13:36:57 +0100 Subject: [PATCH] Enhance jasminsms (#2560) * indent --- notification/jasminsms/httpapi/custom/api.pm | 8 ++- notification/jasminsms/httpapi/mode/alert.pm | 54 +++++++++++++++++--- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/notification/jasminsms/httpapi/custom/api.pm b/notification/jasminsms/httpapi/custom/api.pm index fa42777e1..54bfa5294 100644 --- a/notification/jasminsms/httpapi/custom/api.pm +++ b/notification/jasminsms/httpapi/custom/api.pm @@ -37,7 +37,7 @@ sub new { $options{output}->add_option_msg(short_msg => "Class Custom: Need to specify 'options' argument."); $options{output}->option_exit(); } - + if (!defined($options{noptions})) { $options{options}->add_options(arguments => { 'hostname:s@' => { name => 'hostname' }, @@ -108,7 +108,11 @@ sub send_sms { 'hex-content=' . $options{message} ]; if (defined($options{from}) && $options{from} ne '') { - push @$get_param, 'from=' . $options{from} + push @$get_param, 'from=' . $options{from}; + } + if (defined($options{dlr}) && $options{dlr} eq 'yes') { + push @$get_param, 'dlr=yes', 'dlr-url=' . $options{dlr_url}, + 'dlr-level=' . $options{dlr_level}, 'dlr-method=' . $options{dlr_method}; } my $rv = 'Error sending sms'; diff --git a/notification/jasminsms/httpapi/mode/alert.pm b/notification/jasminsms/httpapi/mode/alert.pm index 26f5c05ed..b3819ab55 100644 --- a/notification/jasminsms/httpapi/mode/alert.pm +++ b/notification/jasminsms/httpapi/mode/alert.pm @@ -26,22 +26,28 @@ use strict; use warnings; use Encode; +my $map_dlr_level = { + 'sms-c' => 1, terminal => 2, both => 3 +}; + sub new { my ($class, %options) = @_; my $self = $class->SUPER::new(package => __PACKAGE__, %options); bless $self, $class; $options{options}->add_options(arguments => { - 'from:s' => { name => 'from'}, - 'to:s' => { name => 'to' }, - 'message:s' => { name => 'message' }, - 'coding:s' => { name => 'coding', default => 8 } + 'from:s' => { name => 'from'}, + 'to:s' => { name => 'to' }, + 'message:s' => { name => 'message' }, + 'coding:s' => { name => 'coding', default => 8 }, + 'dlr-url:s' => { name => 'dlr_url' }, + 'dlr-level:s' => { name => 'dlr_level' }, + 'dlr-method:s' => { name => 'dlr_method' } }); return $self; } - sub check_options { my ($self, %options) = @_; @@ -64,6 +70,26 @@ sub check_options { $self->{output}->add_option_msg(short_msg => 'Please set --message option'); $self->{output}->option_exit(); } + + $self->{dlr_enabled} = 'no'; + my $dlr_options = { dlr_url => 1, dlr_level => 1, dlr_method => 1 }; + foreach (('dlr_url', 'dlr_level', 'dlr_method')) { + if (defined($self->{option_results}->{$_}) && $self->{option_results}->{$_} ne '') { + if (/level/ && !defined($map_dlr_level->{ $self->{option_results}->{$_} })) { + $self->{output}->add_option_msg(short_msg => 'Wrong --dlr-level option'); + $self->{output}->option_exit(); + } elsif (/method/ && $self->{option_results}->{$_} !~ /^GET|POST$/) { + $self->{output}->add_option_msg(short_msg => 'Wrong --dlr-method option'); + $self->{output}->option_exit(); + } + $self->{dlr_enabled} = 'yes'; + delete $dlr_options->{$_}; + } + } + if (scalar(keys %$dlr_options) =~ /1|2/) { + $self->{output}->add_option_msg(short_msg => 'Please set ' . join(' ', (map { s/_/-/g; $_ } keys(%$dlr_options))) . ' option(s)'); + $self->{output}->option_exit(); + } } sub encoding_message { @@ -84,7 +110,11 @@ sub run { to => $self->{option_results}->{to}, from => $self->{option_results}->{from}, message => $self->{option_results}->{message}, - coding => $self->{option_results}->{coding} + coding => $self->{option_results}->{coding}, + dlr => $self->{dlr_enabled}, + dlr_url => $self->{option_results}->{dlr_url}, + dlr_level => $self->{dlr_enabled} eq 'yes' ? $map_dlr_level->{ $self->{option_results}->{dlr_level} } : undef, + dlr_method => $self->{option_results}->{dlr_method} ); if ($response =~ /Error/) { @@ -124,6 +154,18 @@ Specify the message to send. Sets the Data Coding Scheme bits (Default: 8 (UCS2)). +=item B<--dlr-url> + +Sets DLR-URL. + +=item B<--dlr-level> + +Sets DLR level (can be: 'sms-c', 'terminal', 'both'). + +=item B<--dlr-method> + +Sets DLR method (can be: 'GET', 'POST'). + =back =cut