Beispiel #1
0
func (s *StacksWatch) Run() error {
	seen := map[string]struct{}{}
	for {
		rsp, e := client.DescribeStackEvents(&cloudformation.DescribeStackEventsParameters{StackName: s.Name})
		if e != nil {
			fmt.Printf("ERROR: %s\n", e.Error())
		} else {
			events := StackEventsList(rsp.DescribeStackEventsResult.StackEvents)
			sort.Sort(events)
			for _, e := range events {
				_, ok := seen[e.EventId]
				if !ok {
					ph := e.PhysicalResourceId
					fmt.Printf("%s %-24s %-32s %s\n", e.Timestamp.Format(time.RFC3339), maxLen(e.LogicalResourceId, 24), maxLen(ph, 32), e.ResourceStatus)
					switch e.ResourceStatusReason {
					case "", ReasonUserInitiated, ReasonResourceCreationInitiated:
						//
					default:
						fmt.Printf("%20s %s\n", "", gocli.Red(e.ResourceStatusReason))
					}
					seen[e.EventId] = struct{}{}
				}
			}
		}
		time.Sleep(time.Duration(s.Refresh) * time.Second)
	}
	return nil
}
Beispiel #2
0
func run() error {
	b, e := base64.StdEncoding.DecodeString(BUILD_INFO)
	if e != nil {
		return e
	}
	fmt.Println(string(b))
	_ = gocli.Red("test") // just to add external dependencies
	return nil
}
Beispiel #3
0
func (r *hostsList) Run() error {
	// Create an EC2 service object in the "eu-west-1" region
	// Note that you can also configure your region globally by
	// exporting the AWS_REGION environment variable
	svc := ec2.New(session.New(), &aws.Config{Region: aws.String("eu-west-1")})

	// we are only concerned with running instances
	filterChain := &ec2.DescribeInstancesInput{
		Filters: []*ec2.Filter{
			&ec2.Filter{
				Name:   aws.String("instance-state-name"),
				Values: aws.StringSlice([]string{"running"}),
			},
			//&ec2.Filter{
			//	Name:   aws.String("tag:Env"),
			//	Values: aws.StringSlice([]string{"staging"}),
			//},
		},
	}

	// filter by environment
	//Query   string `cli:"arg"`

	// Call the DescribeInstances Operation
	resp, err := svc.DescribeInstances(filterChain)
	if err != nil {
		panic(err)
	}

	// id launch_time ami name ip type revision role
	t := gocli.NewTable()
	t.Header("id", "launch_time", "ami", "name", "ip", "public_ip", "type", "revision", "role")

	instances, _ := awsutil.ValuesAtPath(resp, "Reservations[].Instances[]")
	for _, instance := range instances {
		h := instance.(*ec2.Instance)
		tags := aggregateTags(h.Tags)
		// TODO - calculate role from tags
		role := gocli.Red("NONE")
		t.Add(h.InstanceId, h.LaunchTime.Format("2006-01-02T15:04"), h.ImageId, tags["Name"], h.PrivateIpAddress, h.PublicIpAddress, h.InstanceType, "aabbcc", role)
	}

	t.SortBy = 1
	sort.Sort(sort.Reverse(t))

	fmt.Println(t)
	return nil
}
Beispiel #4
0
func (a *elbDescribeLoadBalancer) Run() error {
	elbClient := elb.NewFromEnv()
	states, e := elbClient.DescribeInstanceHealth(a.Name)
	if e != nil {
		return e
	}
	table := gocli.NewTable()
	for _, state := range states {
		stateString := ""
		if state.State == "InService" {
			stateString = gocli.Green(state.State)
		} else {
			stateString = gocli.Red(state.State)
		}
		table.Add(state.InstanceId, stateString)
	}
	fmt.Println(table)
	return nil
}
Beispiel #5
0
func run() error {
	logger.Printf(gocli.Red("running"))
	return nil
}