blob: 7cf6d87c99697a136f848aacf81cd74a427886c7 (
plain) (
tree)
|
|
package org.openslx.taskmanager.tasks;
import org.openslx.taskmanager.api.SystemCommandTask;
public class Netstat extends SystemCommandTask
{
private final Output status = new Output();
@Override
protected String[] initCommandLine()
{
this.timeoutSeconds = 4;
return new String[] {
"/usr/bin/sudo",
"-n",
"-u", "root",
"/bin/netstat",
"-tulpn"
};
}
@Override
protected boolean processEnded( int exitCode )
{
return exitCode == 0;
}
@Override
protected void processStdOut( String line )
{
status.addMessage( line );
}
@Override
protected void processStdErr( String line )
{
status.addMessage( line );
}
@Override
protected boolean initTask()
{
this.setStatusObject( status );
return true;
}
/**
* Output - contains additional status data of this task
*/
class Output
{
private String messages = null;
private void addMessage( String str )
{
if ( messages == null ) {
messages = str;
} else {
messages += "\n" + str;
}
}
}
}
|