Author: fapeeler
Date: Wed Aug 6 16:27:08 2014
New Revision: 1616270
URL: http://svn.apache.org/r1616270
Log:
VCL-736
added notify_user_console to Windows module
cleaned up utils, removed notify_via_msg and notify_via_wall routines
Modified:
vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
vcl/trunk/managementnode/lib/VCL/inuse.pm
vcl/trunk/managementnode/lib/VCL/utils.pm
Modified: vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm?rev=1616270&r1=1616269&r2=1616270&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/Module/OS/Windows.pm Wed Aug 6 16:27:08
2014
@@ -11879,6 +11879,52 @@ sub get_timezone_offset_minutes {
#/////////////////////////////////////////////////////////////////////////////
+=head2 notify_user_console
+
+ Parameters : message, username(optional)
+ Returns : boolean
+ Description : Send a message to the user on the console
+
+=cut
+
+sub notify_user_console {
+ my $self = shift;
+ if (ref($self) !~ /Module/i) {
+ notify($ERRORS{'CRITICAL'}, 0, "subroutine was called as a
function, it must be called as a class method");
+ return;
+ }
+
+ my $message = shift;
+ if(!$message) {
+ notify($ERRORS{'WARNING'}, 0, "message argument was not
supplied");
+ return;
+ }
+
+ my $username = shift;
+ if (!$username) {
+ $username = $self->data->get_user_login_id();
+ }
+ my $request_forimaging = $self->data->get_request_forimaging();
+ if($request_forimaging) {
+ $username = "Administrator";
+ }
+
+ my $computer_node_name = $self->data->get_computer_node_name();
+ my $system32_path = $self->get_system32_path();
+
+ my $cmd = "$system32_path/msg.exe $username /TIME:180 '$message'";
+ my ($exit_status, $output) = $self->execute($cmd, 1);
+ if (!defined($output)) {
+ notify($ERRORS{'WARNING'}, 0, "failed to execute command to
determine if the '$cmd' shell command exists on $computer_node_name");
+ return;
+ }
+ else {
+ notify($ERRORS{'DEBUG'}, 0, "executed command to determine if
the '$cmd' shell command exists on $computer_node_name");
+ return 1;
+ }
+}
+#/////////////////////////////////////////////////////////////////////////////
+
1;
__END__
Modified: vcl/trunk/managementnode/lib/VCL/inuse.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/inuse.pm?rev=1616270&r1=1616269&r2=1616270&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/inuse.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/inuse.pm Wed Aug 6 16:27:08 2014
@@ -523,12 +523,7 @@ EOF
# Send message to machine
if ($computer_type =~ /blade|virtualmachine/) {
- if ($image_os_type =~ /windows/) {
- # Notify via windows msg cmd
- $user_login_id= "administrator" if($request_forimaging);
- notify_via_msg($computer_short_name, $user_login_id,
$short_message);
- }
- elsif ($image_os_type =~ /osx/){
+ sif ($image_os_type =~ /osx/){
# Notify via oascript
notify_via_oascript($computer_short_name, $user_login_id,
$short_message);
}
@@ -678,15 +673,6 @@ EOF
notify_via_IM($user_imtype_name, $user_im_id, $message);
}
- # Send message to machine
- if ($computer_type =~ /blade|virtualmachine/) {
- if ($image_os_type =~ /windows/) {
- # Notify via windows msg cmd
- $user_login_id= "administrator" if($request_forimaging);
- notify_via_msg($computer_short_name, $user_login_id,
$short_message);
- }
- } ## end if ($computer_type =~ /blade|virtualmachine/)
-
return 1;
} ## end sub _notify_user_disconnect
#/////////////////////////////////////////////////////////////////////////////
Modified: vcl/trunk/managementnode/lib/VCL/utils.pm
URL:
http://svn.apache.org/viewvc/vcl/trunk/managementnode/lib/VCL/utils.pm?rev=1616270&r1=1616269&r2=1616270&view=diff
==============================================================================
--- vcl/trunk/managementnode/lib/VCL/utils.pm (original)
+++ vcl/trunk/managementnode/lib/VCL/utils.pm Wed Aug 6 16:27:08 2014
@@ -191,9 +191,7 @@ our @EXPORT = qw(
normalize_file_path
notify
notify_via_IM
- notify_via_msg
notify_via_oascript
- notify_via_wall
parent_directory_path
preplogfile
read_file_to_array
@@ -2342,123 +2340,6 @@ sub notify_via_oascript {
#/////////////////////////////////////////////////////////////////////////////
-=head2 notify_via_wall
-
- Parameters : empty
- Returns : 0 or 1
- Description : talks to user at the console using wall
-
-=cut
-
-sub notify_via_wall {
- my ($hostname, $username, $string, $OSname, $type) = @_;
- my ($package, $filename, $line, $sub) = caller(0);
- notify($ERRORS{'WARNING'}, 0, "hostname is not defined") if
(!(defined($hostname)));
- notify($ERRORS{'WARNING'}, 0, "username is not defined") if
(!(defined($username)));
- notify($ERRORS{'WARNING'}, 0, "string is not defined") if
(!(defined($string)));
- notify($ERRORS{'WARNING'}, 0, "OSname is not defined") if
(!(defined($OSname)));
- notify($ERRORS{'WARNING'}, 0, "type is not defined") if
(!(defined($type)));
- my @ssh;
- my $n;
- my $identity;
- #create file, copy to remote host, then run wall
- if (open(TMP, ">/tmp/wall.$hostname")) {
- print TMP $string;
- close TMP;
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "could not open tmp file $!");
- }
- my $identity_keys = get_management_node_info()->{keys};
- if ($type eq "blade") {
- #this is only going to be rhel
- if (run_scp_command("/tmp/wall.$hostname",
"$hostname:/root/wall.txt", $identity_keys)) {
- unlink "/tmp/wall.$hostname";
- if (run_ssh_command($hostname, $identity_keys, " cat
/root/wall.txt \| wall; /bin/rm -v /root/wall.txt", "root")) {
- notify($ERRORS{'OK'}, 0, "successfully sent
wall notification to $hostname");
- return 1;
- }
- }
- } ## end if ($type eq "blade")
- elsif ($type eq "lab") {
-
- if (run_scp_command("/tmp/wall.$hostname",
"vclstaff\@$hostname:/home/vclstaff/wall.txt", $identity_keys, 24)) {
- unlink "/tmp/wall.$hostname";
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "could not scp tmp file
for wall notification$!");
- }
-
- if ($OSname =~ /sun4x_/) {
- if (run_ssh_command($hostname, $identity_keys, "wall -a
/home/vclstaff/wall.txt; /bin/rm -v /home/vclstaff/wall.txt", "vclstaff",
"24")) {
- notify($ERRORS{'OK'}, 0, "successfully sent
wall notification to $hostname");
- return 1;
- }
- else {
- notify($ERRORS{'OK'}, 0, "wall notification
$hostname failed ");
- }
- }
- elsif ($OSname =~ /rhel/) {
- if (run_ssh_command($hostname, $identity_keys, "cat
/home/vclstaff/wall.txt \| wall ; /bin/rm -v /home/vclstaff/wall.txt",
"vclstaff", "24")) {
- notify($ERRORS{'OK'}, 0, "successfully sent
wall notification to $hostname");
- return 1;
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "wall
notification $hostname failed ");
- }
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "not an OS I can handle,
os is $OSname");
- }
- return 1;
- } ## end elsif ($type eq "lab") [ if ($type eq "blade")
-} ## end sub notify_via_wall
-
-#/////////////////////////////////////////////////////////////////////////////
-
-=head2 notify_via_msg
-
- Parameters : $node, $user, $message
- Returns : 0 or 1
- Description : using windows msg.exe cmd writes supplied $message
- to windows user console
-
-=cut
-
-sub notify_via_msg {
- my ($node, $user, $message) = @_;
- my ($package, $filename, $line, $sub) = caller(0);
-
- my $osname = lc($^O);
- if ($osname =~ /win/i) {
- notify($ERRORS{'OK'}, 0, "notifying from Windows not yet
supported\n-----\nTo: $user\nNode: $node\n$message\n-----");
- return;
- }
- notify($ERRORS{'WARNING'}, 0, "node is not defined") if
(!(defined($node)));
- notify($ERRORS{'WARNING'}, 0, "message is not defined") if
(!(defined($message)));
- notify($ERRORS{'WARNING'}, 0, "user is not defined") if
(!(defined($user)));
-
- # Escape new lines
- $message =~ s/\n/ /gs;
- $message =~ s/\'/\\\\\\\'/gs;
- notify($ERRORS{'DEBUG'}, 0, "message:\n$message");
-
- my $command = "msg $user /TIME:180 '$message'";
-
- my $identity_keys = get_management_node_info()->{keys};
- if (run_ssh_command($node, $identity_keys, $command)) {
- notify($ERRORS{'OK'}, 0, "successfully sent message to Windows
user $user on $node");
- return 1;
- }
- else {
- notify($ERRORS{'WARNING'}, 0, "failed to send message to
Windows user $user on $node");
- return 0;
- }
-
-} ## end sub notify_via_msg
-
-#/////////////////////////////////////////////////////////////////////////////
-
=head2 getpw
Parameters : length(optional) - if not defined sets to 6