forked from eve-n0rman/structurebot
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathstructurebot.py
90 lines (81 loc) · 4.05 KB
/
structurebot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
from __future__ import absolute_import
import logging
import argparse
from structurebot.config import CONFIG
from structurebot.util import notify_slack, name_to_id
from structurebot.citadels import Structure
from structurebot.assets import Asset
from structurebot.pos import check_pos
parser = argparse.ArgumentParser()
parser.add_argument('--suppress-upcoming-detonations', dest='upcoming_detonations', action='store_false')
parser.add_argument('--suppress-unscheduled-detonations', dest='unscheduled_detonations', action='store_false')
parser.add_argument('--suppress-ansiblex-ozone', dest='ansiblex_ozone', action='store_false')
parser.add_argument('--suppress-fuel-warning', dest='fuel_warning', action='store_false')
parser.add_argument('--suppress-service-state', dest='service_state', action='store_false')
parser.add_argument('--suppress-structure-state', dest='structure_state', action='store_false')
parser.add_argument('--suppress-core-state', dest='core_state', action='store_false')
parser.add_argument('-d', '--debug', action='store_true')
args = parser.parse_args()
debug = CONFIG['DEBUG'] or args.debug
level = logging.WARNING
if debug:
level = logging.INFO
logging.basicConfig(level=level)
pyswagger_logger = logging.getLogger('pyswagger')
pyswagger_logger.setLevel(logging.ERROR)
messages = []
errors = []
corp_name = CONFIG['CORPORATION_NAME']
try:
CONFIG['CORP_ID'] = name_to_id(corp_name, 'corporation')
assetsError = False
assets = None
try:
assets = Asset.from_entity_name(corp_name)
except Exception as e:
assetsError = True
errors.append(str(e))
errors.append(":frogsiren: ********************************************************* :frogsiren:")
errors.append(" Failed to read assets, Ozone and Core checks will be skipped. ")
errors.append(":frogsiren: ********************************************************* :frogsiren:")
structures = Structure.from_corporation(corp_name, assets)
for structure in structures:
message = []
if not structure.accessible:
msg = 'Found an inaccessible citadel ({}) in {}'.format(structure.structure_id, structure.system_id)
messages.append(msg)
continue
if args.unscheduled_detonations and structure.needs_detonation:
message.append('Needs to have an extraction scheduled')
if args.upcoming_detonations and structure.detonates_soon:
message.append('Ready to detonate {}'.format(structure.detonation))
if args.ansiblex_ozone and structure.needs_ozone and not assetsError:
message.append('Low on Liquid Ozone: {}'.format(structure.jump_fuel))
if args.fuel_warning and structure.needs_fuel:
message.append('Runs out of fuel on {}'.format(structure.fuel_expires))
if args.service_state:
if structure.online_services:
message.append('Online Services: {}'.format(', '.join(structure.online_services)))
if structure.offline_services:
message.append('Offline Services: {}'.format(', '.join(structure.offline_services)))
if args.service_state and structure.offline_services:
message.append('Offline services: {}'.format(', '.join(structure.offline_services)))
if args.structure_state and (structure.vulnerable or structure.reinforced):
state = structure.state.replace('_', ' ').title()
message.append('{} until {}'.format(state, structure.state_timer_end))
if args.core_state and structure.needs_core and not assetsError:
message.append('No core installed')
if message:
messages.append(u'\n'.join([u'{}'.format(structure.name)] + message))
messages += check_pos(corp_name, assets)
except Exception as e:
if debug:
raise
else:
messages = [str(e)]
if messages:
messages = sorted(messages)
messages.insert(0, 'Upcoming {} Structure Maintenance Tasks'.format(corp_name))
messages = errors + messages
notify_slack(messages)