Добрый день,
используем скриптовый шлюз для микротика:
Код:
import java.util.*;
import java.util.regex.*;
import ru.bitel.bgbilling.common.*;
import bitel.billing.common.module.ipn.*;
import bitel.billing.server.ipn.bean.*;
import bitel.billing.server.ipn.*;
import bitel.billing.server.util.ssh.*;
import bitel.billing.server.util.*;
import bitel.billing.server.util.ssh.SSHSession;
protected void doSync()
{
host = gate.getHost();
port = gate.getPort();
gateSetup = new DefaultServerSetup( gate.getConfig(), "\r\n" );
login = gateSetup.getStringValue( "login", "root" );
pswd = gate.getKeyword();
if ( log.isDebugEnabled() )
{
log.debug( " gate: " + host + ":" + port + " login: " + login + " pswd: " + pswd );
}
session = null;
try
{
session = new SSHSessionExec( host, port, login, pswd );
address_list = session.command( "ip firewall address-list print without-paging" );
new_address_list = null;
for ( UserStatus status : statusList )
{
cid = status.contractId;
ruleType = status.ruleType;
rule_id = 0;
if (ruleType != null)
{
rule_id = ruleType.getId();
};
rules = null;
if (address_list.indexOf( "cid="+cid+";rule_id="+rule_id+";") != -1)
{
// правило для этого договора есть на шлюзе
if ( status.status > 0 )
{
if ( status.status == IPNContractStatus.STATUS_REMOVED )
{
// удаляем
rules = getDeleteRules( status );
}
else
{
// закрываем
rules = getCloseRules( status );
};
};
}
else if ( status.status == IPNContractStatus.STATUS_OPEN )
{
//открываем
rules = getOpenRules( status );
};
if (rules != null){
for ( String rule : rules )
{
p = Pattern.compile("rule_id");
m = p.matcher(rule);
if (new_address_list == null)
{
new_address_list = "";
};
new_address_list = new_address_list + m.replaceAll("rule_id="+rule_id) + "\n";
};
};
}
if (new_address_list != null){
print(address_list);
print(new_address_list);
result = session.command(new_address_list);
print(result);
};
}
catch( Exception e )
{
throw new RuntimeException( e );
}
finally
{
if ( session != null )
{
session.disconnect();
}
}
}
private getOpenRules( status )
{
return getRules( status, "\\[OPEN\\](.*)\\[/OPEN\\]" );
}
private getCloseRules( status )
{
return getRules( status, "\\[CLOSE\\](.*)\\[/CLOSE\\]" );
}
private getDeleteRules( status )
{
return getRules( status, "\\[DELETE\\](.*)\\[/DELETE\\]" );
}
private getRules( status, template )
{
// пользовательское правило, без типа - то все оставляем как есть
rule = status.rule.getRuleText();
// типизированное правило
if ( status.ruleType != null )
{
rule = generateRule( rule, status.gateType, status.ruleType, status.contractId );
}
pattern = Pattern.compile( template, Pattern.DOTALL );
m = pattern.matcher( rule );
if ( m.find() )
{
rule = m.group( 1 );
}
rule.replaceAll( "\r", "" );
return rule.split( "\n" );
}
private generateRule( addresses, gateType, ruleType, cid )
{
String rule;
replacements = new HashMap();
replacements.put( "\\{CID\\}", String.valueOf( cid ) );
ruleText = ManadUtils.getRule( gateType, ruleType );
rule = ManadUtils.generateRule( ruleText, addresses, replacements, ruleType );
return rule;
}
До недавнего времени, благодаря хелпдеску, этот скрипт обрабатывал текущие правила в договоре и прописывал их на микротик, но после одного из обновлений что то перестало работать
в scheduler.out
Код:
java.lang.RuntimeException: TargetError : at Line: 87 : in file: inline evaluation of: ``import java.util.*; import java.util.regex.*; import ru.bitel.bgbilling.common.* . . . '' : throw new RuntimeException ( e ) ;
Target exception: java.lang.RuntimeException: com.jcraft.jsch.JSchException: ChannelExec
at bitel.billing.server.ipn.GateWorker$Scripter.runScriptSync(GateWorker.java:240)
at bitel.billing.server.ipn.GateWorker.runSync(GateWorker.java:107)
at bitel.billing.server.ipn.GateWorker.run(GateWorker.java:85)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: TargetError : at Line: 87 : in file: inline evaluation of: ``import java.util.*; import java.util.regex.*; import ru.bitel.bgbilling.common.* . . . '' : throw new RuntimeException ( e ) ;
Target exception: java.lang.RuntimeException: com.jcraft.jsch.JSchException: ChannelExec
at bsh.BSHThrowStatement.eval(Unknown Source)
at bsh.BSHBlock.evalBlock(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BSHTryStatement.eval(Unknown Source)
at bsh.BSHBlock.evalBlock(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BshMethod.invokeImpl(Unknown Source)
at bsh.BshMethod.invoke(Unknown Source)
at bsh.BshMethod.invoke(Unknown Source)
at bitel.billing.server.ipn.GateWorker$Scripter.invokeMethod(GateWorker.java:266)
at bitel.billing.server.ipn.GateWorker$Scripter.runScriptSync(GateWorker.java:227)
... 8 more
в scheduler.error.log
Код:
scheduler 05-01/05:13:15 ERROR [pool-7-thread-2] MikrotikGateWorker - Eval error2: TargetError
TargetError : at Line: 87 : in file: inline evaluation of: ``import java.util.*; import java.util.regex.*; import ru.bitel.bgbilling.common.* . . . '' : throw new RuntimeException ( e ) ;
Target exception: java.lang.RuntimeException: com.jcraft.jsch.JSchException: ChannelExec
at bsh.BSHThrowStatement.eval(Unknown Source)
at bsh.BSHBlock.evalBlock(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BSHTryStatement.eval(Unknown Source)
at bsh.BSHBlock.evalBlock(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BshMethod.invokeImpl(Unknown Source)
at bsh.BshMethod.invoke(Unknown Source)
at bsh.BshMethod.invoke(Unknown Source)
at bitel.billing.server.ipn.GateWorker$Scripter.invokeMethod(GateWorker.java:266)
at bitel.billing.server.ipn.GateWorker$Scripter.runScriptSync(GateWorker.java:227)
at bitel.billing.server.ipn.GateWorker.runSync(GateWorker.java:107)
at bitel.billing.server.ipn.GateWorker.run(GateWorker.java:85)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
scheduler 05-01/05:13:15 ERROR [pool-7-thread-2] MikrotikGateWorker - Gate unaccesible - 172.31.0.253
scheduler 05-01/05:13:15 ERROR [pool-7-thread-2] MikrotikGateWorker - -------------------------
scheduler 05-01/05:13:15 ERROR [pool-7-thread-2] MikrotikGateWorker - error: TargetError : at Line: 87 : in file: inline evaluation of: ``import java.util.*; import java.util.regex.*; import ru.bitel.bgbilling.common.* . . . '' : throw new RuntimeException ( e ) ;
Target exception: java.lang.RuntimeException: com.jcraft.jsch.JSchException: ChannelExec
java.lang.RuntimeException: TargetError : at Line: 87 : in file: inline evaluation of: ``import java.util.*; import java.util.regex.*; import ru.bitel.bgbilling.common.* . . . '' : throw new RuntimeException ( e ) ;
Target exception: java.lang.RuntimeException: com.jcraft.jsch.JSchException: ChannelExec
at bitel.billing.server.ipn.GateWorker$Scripter.runScriptSync(GateWorker.java:240)
at bitel.billing.server.ipn.GateWorker.runSync(GateWorker.java:107)
at bitel.billing.server.ipn.GateWorker.run(GateWorker.java:85)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: TargetError : at Line: 87 : in file: inline evaluation of: ``import java.util.*; import java.util.regex.*; import ru.bitel.bgbilling.common.* . . . '' : throw new RuntimeException ( e ) ;
Target exception: java.lang.RuntimeException: com.jcraft.jsch.JSchException: ChannelExec
at bsh.BSHThrowStatement.eval(Unknown Source)
at bsh.BSHBlock.evalBlock(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BSHTryStatement.eval(Unknown Source)
at bsh.BSHBlock.evalBlock(Unknown Source)
at bsh.BSHBlock.eval(Unknown Source)
at bsh.BshMethod.invokeImpl(Unknown Source)
at bsh.BshMethod.invoke(Unknown Source)
at bsh.BshMethod.invoke(Unknown Source)
at bitel.billing.server.ipn.GateWorker$Scripter.invokeMethod(GateWorker.java:266)
at bitel.billing.server.ipn.GateWorker$Scripter.runScriptSync(GateWorker.java:227)
... 8 more
bill вер. 4.6 сборка 225 от 02.04.2010 16:26:09
ipn вер. 4.6 сборка 246 от 21.04.2010 19:04:28
os centos java 1.6.0_15
mikrotik routeros 4.6
сейчас задача проверки шлюзов не меняет правило на микротике, хотя если руками закрыть\открыть шлюз, то все в порядке.
что поломалось и как починить?