我正在创建一个日志解析器,它能够在写入日志时“流”化。 日志驻留在远程主机上,因此我使用组合创建文件处理程序 SSH和尾巴。以下工作非常好,但我确实有一些关于错误处理的问题。
如果用户在报警延迟到期之前没有输入SSH连接的密码,则报警将开始触发。这导致控制台被清除,因此不清楚是否需要输入密码。
如果我输入了错误的密码,我仍然启用警报,导致屏幕清除等等......
Password:
Password:
Password:
Permission denied (publickey,keyboard-interactive).
如果我提供一个不存在的日志文件名,代码会继续......
tail: cannot open `/path_to_log/mylog.logXXXX' for reading: No such file or directory
tail: no files remaining
所以,我的问题是添加一些额外的错误处理的最佳方法是什么。或者,File :: Tail模块可以与SSH,telnet,rlogin等结合使用以提供相同的功能吗?
谢谢!
my $stopMsg = "Use CTRL+C to stop streaming at any time...\n";
my $SSH = sprintf "ssh %s@%s tail -f %s | ", $user, $host, $log;
printf "Log: %s\n", $log;
printf "Handle: %s\n", $SSH;
my $errMsg = sprintf "Couldn't establish SSH connection to \"%s\":",
$host;
open my $pipe, $SSH or error( $errMsg );
my $loadTime = time;
printf $stopMsg;
setSignalHandler( 'INT', sub{ stopAlarm( TRUE ); } );
startAlarm( $delay,
$interval,
sub { system "clear"; $handler->( \@sysLogArr ); printf $stopMsg; } );
while ( alarmHandlerSet() )
{
my $data = <$pipe>;
next unless defined $data;
mapSysLog( line => $data,
arrRef => $logRef,
varRef => \%sysLogVars,
dbRef => $dbRef );
}
clearSignalHandler( 'INT' );
sub error(@)
{
my $color = "BOLD";
$color = $CONFIG{errorPrinter} if ( $CONFIG{colorEnable} &&
defined $CONFIG{errorPrinter} );
color2PrinterRef( $color )->( "\nERROR: " );
printf "%s\n", shift;
printf " %s\n", $_ foreach ( @_ );
printf "Called From: %s::%d\n", (caller)[1], (caller)[2];
printf "\n";
exit EXIT_FAILURE;
}