Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches #295

Merged
merged 7 commits into from
Apr 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include requirements.txt
include README.md
4 changes: 2 additions & 2 deletions pyouroboros/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
VERSION = "1.3.1"
BRANCH = "master"
VERSION = "1.4.0"
BRANCH = "develop"
6 changes: 4 additions & 2 deletions pyouroboros/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Config(object):
'PROMETHEUS_PORT', 'NOTIFIERS', 'REPO_USER', 'REPO_PASS', 'CLEANUP', 'RUN_ONCE', 'CRON',
'INFLUX_URL', 'INFLUX_PORT', 'INFLUX_USERNAME', 'INFLUX_PASSWORD', 'INFLUX_DATABASE', 'INFLUX_SSL',
'INFLUX_VERIFY_SSL', 'DATA_EXPORT', 'SELF_UPDATE', 'LABEL_ENABLE', 'DOCKER_TLS', 'LABELS_ONLY',
'DRY_RUN', 'HOSTNAME', 'DOCKER_TLS_VERIFY', 'SWARM']
'DRY_RUN', 'HOSTNAME', 'DOCKER_TLS_VERIFY', 'SWARM', 'SKIP_STARTUP_NOTIFICATIONS']

hostname = environ.get('HOSTNAME')
interval = 300
Expand Down Expand Up @@ -45,6 +45,7 @@ class Config(object):
influx_database = None

notifiers = []
skip_startup_notifications = False

def __init__(self, environment_vars, cli_args):
self.cli_args = cli_args
Expand Down Expand Up @@ -91,7 +92,8 @@ def parse(self):
except ValueError as e:
print(e)
elif option in ['CLEANUP', 'RUN_ONCE', 'INFLUX_SSL', 'INFLUX_VERIFY_SSL', 'DRY_RUN', 'SWARM',
'SELF_UPDATE', 'LABEL_ENABLE', 'DOCKER_TLS', 'LABELS_ONLY', 'DOCKER_TLS_VERIFY']:
'SELF_UPDATE', 'LABEL_ENABLE', 'DOCKER_TLS', 'LABELS_ONLY', 'DOCKER_TLS_VERIFY',
'SKIP_STARTUP_NOTIFICATIONS']:
if env_opt.lower() in ['true', 'yes']:
setattr(self, option.lower(), True)
elif env_opt.lower() in ['false', 'no']:
Expand Down
21 changes: 13 additions & 8 deletions pyouroboros/dockerclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,15 @@ def recreate(self, container, latest_image):
new_network_config = {
'container': new_container,
'aliases': network_config['Aliases'],
'links': network_config['Links'],
'ipv4_address': network_config['IPAddress'],
'ipv6_address': network_config['GlobalIPv6Address']
'links': network_config['Links']
}
if network_config['IPAMConfig']:
new_network_config.update(
{
'ipv4_address': network_config['IPAddress'],
'ipv6_address': network_config['GlobalIPv6Address']
}
)
try:
network.connect(**new_network_config)
except APIError as e:
Expand Down Expand Up @@ -229,10 +234,10 @@ def monitor_filter(self):

# Socket Functions
def self_check(self):
self.monitored = self.monitor_filter()
me_list = [container for container in self.monitored if 'ouroboros' in container.name]
if len(me_list) > 1:
self.update_self(count=2, me_list=me_list)
if self.config.self_update:
me_list = [container for container in self.client.containers.list() if 'ouroboros' in container.name]
if len(me_list) > 1:
self.update_self(count=2, me_list=me_list)

def socket_check(self):
depends_on_names = []
Expand Down Expand Up @@ -347,7 +352,7 @@ def update(self):
def update_self(self, count=None, old_container=None, me_list=None, new_image=None):
if count == 2:
self.logger.debug('God im messy... cleaning myself up.')
old_me_id = me_list[0]['Id'] if me_list[0]['Created'] < me_list[1]['Created'] else me_list[1]['Id']
old_me_id = me_list[0].id if me_list[0].attrs['Created'] < me_list[1].attrs['Created'] else me_list[1].id
old_me = self.client.containers.get(old_me_id)
old_me_image_id = old_me.image.id

Expand Down
3 changes: 2 additions & 1 deletion pyouroboros/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def set_properties(old, new, self_name=None):
'host_config': old.attrs['HostConfig'],
'labels': old.attrs['Config']['Labels'],
'entrypoint': old.attrs['Config']['Entrypoint'],
'environment': old.attrs['Config']['Env']
'environment': old.attrs['Config']['Env'],
'healthcheck': old.attrs['Config'].get('Healthcheck', None)
}

return properties
Expand Down
7 changes: 6 additions & 1 deletion pyouroboros/ouroboros.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ def main():
data_group.add_argument('-V', '--influx-verify-ssl', default=Config.influx_verify_ssl, dest='INFLUX_VERIFY_SSL',
action='store_true', help='Verify SSL certificate when connecting to influxdb')

docker_group.add_argument('--skip-startup-notifications', default=Config.skip_startup_notifications,
dest='SKIP_STARTUP_NOTIFICATIONS', action='store_true',
help='Do not send ouroboros notifications when starting')

args = parser.parse_args()

if environ.get('LOG_LEVEL'):
Expand Down Expand Up @@ -194,7 +198,8 @@ def main():
now = datetime.now(timezone.utc).astimezone()
next_run = (now + timedelta(0, config.interval)).strftime("%Y-%m-%d %H:%M:%S")

notification_manager.send(kind='startup', next_run=next_run)
if not config.skip_startup_notifications:
notification_manager.send(kind='startup', next_run=next_run)

while scheduler.get_jobs():
sleep(1)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ docker>=3.7.0
prometheus_client>=0.5.0
requests>=2.21.0
influxdb>=5.2.1
apprise>=0.5.2
apprise>=0.7.4
apscheduler>=3.5.3