开发者

Groovy - how to set parameter external command

开发者 https://www.devze.com 2023-04-10 14:50 出处:网络
I have a soft HP BSM. Actions for operators will write in Groovy script. this is example: import java.util.List;

I have a soft HP BSM. Actions for operators will write in Groovy script.

this is example:

import java.util.List;
import com.hp.opr.api.scripting.Action;
import com.hp.opr.api.scripting.Event;
import com.hp.opr.api.scripting.EventActionFlag;
import com.hp.opr.api.scripting.LifecycleState;
import com.hp.opr.api.scripting.MatchInfo;
import com.hp.opr.api.scripting.NodeInfo;
import com.hp.opr.api.scripting.PolicyType;
import com.hp.opr.api.scripting.Priority;
import com.hp.opr.api.scripting.ResolutionHints;
import com.hp.opr.api.scripting.Severity;

/*
 * This example set all possible event attribute to some example values.
 */

class SimpleExample_new
{
  def init()
  {

    }

    def destroy()
    {

    }

    def process(List<Event> events)
    {
          events.each {
              event -> modifyEvent(event); 
"cmd.exe /c C:\\test\\sd_event.exe -f C:\\test\\sd_event.ini -v event_id=2 description='$description' status=Registered priority=low".execute().text

            }
    }

    def modifyEvent(Event event)
    {
// "cmd.exe /c C:\\test\\sd_event.exe -f C:\\test\\sd_event.ini -v event_id=10 description='$description' status=Registered priority=low".execute().text

    String application = event.getApplication();
    event.setApplication("Modified by ostap: " + application);

    String description = event.getDescription();
    event.setDescription("Modified by ostap: " + d开发者_运维百科escription);

    long groupId = event.getAssignedGroupId();
    event.setAssignedGroupId(groupId);

    int assignedUserId = event.getAssignedUserId();
    event.setAssignedUserId(assignedUserId);

     String category = event.getCategory();
    event.setCategory("Modified by EPI: " + category);

    String correlationKeyPattern = event.getCloseKeyPattern();
    event.setCloseKeyPattern("Modified by EPI: " + correlationKeyPattern);

    String etiInfo = event.getEtiHint();
    event.setEtiHint(etiInfo);

    String correlationKey = event.getKey();
    event.setKey("Modified by EPI: " + correlationKey);

    MatchInfo matchInfo = createSampleMatchInfo();
    event.setMatchInfo(matchInfo);

    event.setNoDedup(true);

    ResolutionHints hints = createSampleResolutionHints();

    event.setNodeHints(hints);

    String object = event.getObject();
    event.setObject("Modified by EPI: " + object);

    String omServiceId = event.getOmServiceId();
    event.setOmServiceId(omServiceId);

    String omUser = event.getOmUser();
    event.setOmUser(omUser);

    String originalText = event.getOriginalData();
    event.setOriginalData("Modified by EPI: " + originalText);

    String originalId = event.getOriginalId();
    event.setOriginalId(originalId);

    event.setSeverity(Severity.MINOR);

    String solution = event.getSolution();
    event.setSolution("Modified by ostap: " + solution);

    ResolutionHints sourceCiHints = createSampleResolutionHints();
    event.setSourceCiHints(sourceCiHints);

    event.setState(LifecycleState.IN_PROGRESS);

    String subCategory = event.getSubCategory();
    event.setSubCategory("Modified by EPI: " + subCategory);

    event.setTimeReceived(new Date());

    String title = event.getTitle();
    event.setTitle("Modified by EPI: " + title);

    String type = event.getType();
    event.setType("Modified by EPI: " + type);

    }

  def ResolutionHints createSampleResolutionHints()
  {
    ResolutionHints hints = new ResolutionHints(false);

    hints.setCoreId("CoreId");
    hints.setDnsName("mydqdn.com");
    hints.setHint("My Hint");
    hints.setIpAddress("0.0.0.0");
    return hints;
  }

  def MatchInfo createSampleMatchInfo()
  {
    MatchInfo matchInfo = new MatchInfo(false);

    matchInfo.setConditionId("conditionId");
    matchInfo.setPolicyName("policyName");
    matchInfo.setPolicyType(PolicyType.CONSOLE);
    return matchInfo;
  }

}

And I want modify example.

I want get "description" and set(put) this "description" to external command (sd_event.exe)

cmd.exe /c C:\\test\\sd_event.exe -f C:\\test\\sd_event.ini -v event_id=50 description=____  status=Registered priority=low".execute().text

I try also run:

cmd.exe /c C:\\test\\mybatch.bat".execute().text  

but i don't know how to put parametres to bat file

mybatch.bat:

C:\test\sd_event.exe -f sd_event.ini -v event_id=5 description=%1 status="Registered" priority=low


Due to the formatting and errors in your code, it's hard to see what is going on, or what you are asking...

When you have:

String description = event.getDescription();

What is event? I can only see a List of events in that function...

Assuming this is just a problem with cut and paste, I think the answer you are looking for is:

"cmd.exe /c C:\test\sd_event.exe -f C:\test\sd_event.ini -v event_id=50 description='$description' status=Registered priority=low".execute().text

But as I said, I'm not sure... You will have to write the output of that function to result.txt yourself, as you cannot do redirection that way when calling the shell from Java/Groovy

0

精彩评论

暂无评论...
验证码 换一张
取 消