diff options
Diffstat (limited to 'lisp/aws')
| -rw-r--r-- | lisp/aws/aws.lisp | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/lisp/aws/aws.lisp b/lisp/aws/aws.lisp index f5d6b93..ab6dcc8 100644 --- a/lisp/aws/aws.lisp +++ b/lisp/aws/aws.lisp @@ -81,6 +81,48 @@ :accessor passphrase)) (:documentation "")) +(defclass aws-targetgroup (aws) + ((name :initarg :name + :initform nil + :accessor name) + (arn :initarg :arn + :initform nil + :accessor arn) + (protocol :initarg :protocol + :initform nil + :accessor protocol) + (port :initarg :port + :initform nil + :accessor port) + (healthy-p :initarg :healthy-p + :initform nil + :accessor healthy-p) + (stdout :initarg :stdout + :initform nil + :accessor stdout) + (filter :initarg :filter + :initform nil + :accessor filter) + (targets :initarg :targets + :initform nil + :accessor targets)) + (:documentation "")) + +(defclass aws-target () + ((instance-id :initarg :instance-id + :initform nil + :accessor instance-id) + (port :initarg :port + :initform nil + :accessor port) + (state :initarg :state + :initform nil + :accessor state) + (healthy-p :initarg :healthy-p + :initform nil + :accessor healthy-p)) + (:documentation "")) + (defclass aws-ssm-parameter (aws) ((name :initarg :name :initform nil @@ -130,6 +172,66 @@ :instances (loop for instance in (cdr (assoc :*instances asg)) collect (cdr (assoc :*instance-id instance))))))) +(defmethod get-targetgroups ((aws-targetgroup aws-targetgroup)) + (let ((command "aws elbv2 describe-target-groups")) + (sort (loop for targetgroup in (cdar (run-aws-cli aws-targetgroup command)) + when (org-ckons-core::match-it (if (string= (filter aws-targetgroup) "all") + "" + (filter aws-targetgroup)) + (cdr (assoc :*target-group-name targetgroup))) + collect (let ((targetgroup (make-instance 'aws-targetgroup + :profile (profile aws-targetgroup) + :region (region aws-targetgroup) + :name (cdr (assoc :*target-group-name targetgroup)) + :arn (cdr (assoc :*target-group-arn targetgroup)) + :protocol (cdr (assoc :*protocol targetgroup)) + :port (cdr (assoc :*port targetgroup))))) + (setf (targets targetgroup) (get-targets targetgroup)) + (setf (healthy-p targetgroup) (get-targetgroup-health targetgroup)) + targetgroup)) + (lambda (x y) (string< (name x) (name y)))))) + +(defmethod get-targets ((aws-targetgroup aws-targetgroup)) + (let ((command (format nil + "aws elbv2 describe-target-health --target-group-arn ~a" + (arn aws-targetgroup)))) + (loop for target in (cdar (run-aws-cli aws-targetgroup command)) + collect (make-instance 'aws-target + :instance-id (cdr (assoc :*id (cdr (assoc :*target target)))) + :port (cdr (assoc :*port (cdr (assoc :*target target)))) + :state (cdr (assoc :*state (cdr (assoc :*target-health target)))) + :healthy-p (string= (cdr (assoc :*state (cdr (assoc :*target-health target)))) "healthy"))))) + +(defmethod get-targetgroup-health ((aws-targetgroup aws-targetgroup)) + (let ((states (loop for target in (targets aws-targetgroup) + collect (healthy-p target)))) + (= (length states) + (length (remove-if 'null states))))) + +(defmethod get-aws-unhealthy-targetgroups ((aws-targetgroup aws-targetgroup)) + (enqueue *queue-aws* aws-targetgroup)) + +(defmethod bg-perform ((aws-targetgroup aws-targetgroup)) + (let ((output (make-array '(0) :element-type 'character :fill-pointer 0 :adjustable t)) + (targetgroups (get-targetgroups aws-targetgroup))) + (with-output-to-string (stream output) + (loop for targetgroup in targetgroups + when (not (healthy-p targetgroup)) + do (format stream + "~a~t~a~t~a~%" + (name targetgroup) + (arn targetgroup) + (port targetgroup)) + (loop for target in (targets targetgroup) + when (not (healthy-p target)) + do (format stream + "~t~a~t~a~%" + (instance-id target) + (state target))) + (format stream "~%"))) + (with-open-file (stream (stdout aws-targetgroup) :direction :output :if-exists :append :if-does-not-exist :create) + (format stream output)))) + (defmethod get-certificates ((aws aws) &optional filter) (sort (loop for cert in (cdr (assoc :*certificate-summary-list (run-aws-cli aws "aws acm list-certificates"))) when (or (and (null filter) |
