summaryrefslogtreecommitdiff
path: root/lib/App/smsg/Command/Status.pm
blob: 27e3814a4b55f23a10d5531fb794c7f1fea4cdc3 (plain)
  1. package App::smsg::Command::Status;
  2. use 5.010;
  3. use strict;
  4. use warnings;
  5. use utf8;
  6. BEGIN {
  7. $App::smsg::Command::Status::AUTHORITY = 'https://dr.jones.dk/me#me';
  8. $App::smsg::Command::Status::VERSION = '0.001';
  9. }
  10. use App::smsg -command;
  11. use namespace::clean;
  12. use NetSDS::Kannel;
  13. use constant abstract => q (Check status of platform(s).);
  14. use constant usage_desc => '%c status %o <platform>...';
  15. use constant description => <<'DESCRIPTION';
  16. Connect to one or more platforms (Kannel, Jabber, IRC etc.) and check
  17. operational status.
  18. DESCRIPTION
  19. use constant opt_spec => (
  20. ['kannelserver=s', "the Kannel server to connect to",
  21. {default => 'localhost'}],
  22. ['kanneladminport=i', "the Kannel admin port to connect to",
  23. {default => 13000}],
  24. ['kanneladminpasswd=s', "the Kannel admin password to authenticate with",
  25. {default => ''}],
  26. ['kannelsendsmsport=i', "the Kannel sendsms port to connect to",
  27. {default => 13013}],
  28. ['kannelsendsmsuser=s', "the Kannel sendsms user to authenticate as",
  29. {default => 'tester'}],
  30. ['kannelsendsmspasswd=s', "the Kannel sendsms password to authenticate with",
  31. {default => 'foobar'}],
  32. ['kannelsmsc=s', "the Kannel SMSC to correspond with"],
  33. [],
  34. # TODO ['f|follow', "keep connection open and emit each change of state"],
  35. # [],
  36. # [ 'verbose|v', "print extra stuff"],
  37. [ 'debug', "print debug stuff"],
  38. );
  39. sub execute {
  40. my ($self, $opt, $args) = @_;
  41. # TODO: support overriding full URL
  42. # TODO: use URI module to construct URL
  43. my $kannel = NetSDS::Kannel->new(
  44. admin_url => 'http://' . $opt->kannelserver . ':' . $opt->kanneladminport . '/',
  45. admin_passwd => $opt->kanneladminpasswd,
  46. sendsms_url => 'http://' . $opt->kannelserver . ':' . $opt->kannelsendsmsport . '/cgi-bin/sendsms',
  47. sendsms_user => $opt->kannelsendsmsuser,
  48. sendsms_passwd => $opt->kannelsendsmspasswd,
  49. default_smsc => $opt->kannelsmsc,
  50. );
  51. my $status = $kannel->status();
  52. if ($opt->debug) {
  53. use Data::Dump;
  54. ddx $status;
  55. }
  56. print $$status{status}."\n";
  57. for my $i ( 0 .. $#{ $$status{smsc} }) {
  58. print $$status{smsc}[$i]{id}.': '.$$status{smsc}[$i]{status}."\n";
  59. }
  60. }
  61. 1;