Skip to content

Commit

Permalink
#1906 show age
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Mar 1, 2024
1 parent 2085eb5 commit eed9ab7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/rultor/agents/Agents.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ public Agent agent(final Talk talk, final Profile profile)
new Agent.Quiet(new DescribesInstance(aws)),
new Agent.Quiet(
new ConnectsInstance(
aws,
new PfShell(
profile,
"none",
Expand Down
22 changes: 19 additions & 3 deletions src/main/java/com/rultor/agents/aws/ConnectsInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@
*/
package com.rultor.agents.aws;

import com.amazonaws.services.ec2.model.DescribeInstancesRequest;
import com.jcabi.aspects.Immutable;
import com.jcabi.log.Logger;
import com.jcabi.ssh.Shell;
import com.jcabi.xml.XML;
import com.rultor.agents.AbstractAgent;
import com.rultor.agents.shells.PfShell;
import java.io.IOException;
import java.util.Date;
import lombok.ToString;
import org.xembly.Directive;
import org.xembly.Directives;
Expand All @@ -49,21 +51,28 @@
@ToString
public final class ConnectsInstance extends AbstractAgent {

/**
* AWS Client.
*/
private final transient AwsEc2 api;

/**
* Shell.
*/
private final transient PfShell shell;

/**
* Ctor.
* @param aws API
* @param shll The shell
*/
public ConnectsInstance(final PfShell shll) {
public ConnectsInstance(final AwsEc2 aws, final PfShell shll) {
super(
"/talk[daemon and not(shell)]",
"/talk/ec2/instance",
"/talk/ec2/host"
);
this.api = aws;
this.shell = shll;
}

Expand All @@ -88,9 +97,16 @@ public Iterable<Directive> process(final XML xml) throws IOException {
instance, host
);
} else {
final long age = new Date().getTime() - this.api.aws()
.describeInstances(
new DescribeInstancesRequest().withInstanceIds(instance)
)
.getReservations().get(0)
.getInstances().get(0)
.getLaunchTime().getTime();
Logger.warn(
this, "Can't connect to AWS instance %s at %s",
instance, host
this, "Can't connect to AWS instance %s at %s (%[ms]s old)",
instance, host, age
);
}
return dirs;
Expand Down

0 comments on commit eed9ab7

Please sign in to comment.