@@ -1264,18 +1264,102 @@ def alert_slack(alert, metric, context):
1264
1264
else :
1265
1265
logger .info ('alert_slack - sent slack message' )
1266
1266
if slack_thread_updates :
1267
+ # @added 20190508 - Bug #2986: New slack messaging does not handle public channel
1268
+ # Issue #111: New slack messaging does not handle public channel
1269
+ # The sc.api_call 'files.upload' response which generates
1270
+ # slack_file_upload has a different structure depending
1271
+ # on whether a channel is private or public. That also
1272
+ # goes for free or hosted slack too.
1273
+ slack_group = None
1274
+ slack_group_list = None
1275
+
1267
1276
# This is basically the channel id of your channel, the
1268
1277
# name could be used so that if in future it is used or
1269
1278
# displayed in a UI
1279
+ # @modified 20190508 - Bug #2986: New slack messaging does not handle public channel
1280
+ # Issue #111: New slack messaging does not handle public channel
1281
+ # This block only works for free slack workspace private
1282
+ # channels. Although this should be handled in the
1283
+ # SLACK_OPTS as slack_account_type: 'free|hosted' and
1284
+ # default_channel_type = 'private|public', it is going
1285
+ # to be handled in the code for the time being so as not
1286
+ # to inconvience users to update their settings.py for
1287
+ # v.1.2.17 # TODO next release with settings change add
1288
+ # these.
1289
+ # try:
1290
+ # slack_group = slack_file_upload['file']['groups'][0].encode('utf-8')
1291
+ # slack_group_list = slack_file_upload['file']['shares']['private'][slack_group]
1292
+ # slack_thread_ts = slack_group_list[0]['ts'].encode('utf-8')
1293
+ # logger.info('alert_slack - slack group is %s and the slack_thread_ts is %s' % (
1294
+ # str(slack_group), str(slack_thread_ts)))
1295
+ # except:
1296
+ # logger.info(traceback.format_exc())
1297
+ # logger.error('error :: alert_slack - faied to determine slack_thread_ts')
1298
+
1299
+ slack_group = None
1300
+ slack_group_trace_groups = None
1301
+ slack_group_trace_channels = None
1270
1302
try :
1271
1303
slack_group = slack_file_upload ['file' ]['groups' ][0 ].encode ('utf-8' )
1304
+ logger .info ('alert_slack - slack group has been set from \' groups\' as %s' % (
1305
+ str (slack_group )))
1272
1306
slack_group_list = slack_file_upload ['file' ]['shares' ]['private' ][slack_group ]
1273
1307
slack_thread_ts = slack_group_list [0 ]['ts' ].encode ('utf-8' )
1274
1308
logger .info ('alert_slack - slack group is %s and the slack_thread_ts is %s' % (
1275
1309
str (slack_group ), str (slack_thread_ts )))
1276
1310
except :
1277
- logger .info (traceback .format_exc ())
1278
- logger .error ('error :: alert_slack - faied to determine slack_thread_ts' )
1311
+ slack_group_trace_groups = traceback .format_exc ()
1312
+ logger .info ('alert_slack - failed to determine slack_group using groups' )
1313
+ if not slack_group :
1314
+ # Try by channel
1315
+ try :
1316
+ slack_group = slack_file_upload ['file' ]['channels' ][0 ].encode ('utf-8' )
1317
+ logger .info ('alert_slack - slack group has been set from \' channels\' as %s' % (
1318
+ str (slack_group )))
1319
+ except :
1320
+ slack_group_trace_channels = traceback .format_exc ()
1321
+ logger .info ('alert_slack - failed to determine slack_group using channels' )
1322
+ logger .error ('error :: alert_slack - failed to determine slack_group using groups or channels' )
1323
+ logger .error ('error :: alert_slack - traceback from slack_group_trace_groups follows:' )
1324
+ logger .error (str (slack_group_trace_groups ))
1325
+ logger .error ('error :: alert_slack - traceback from slack_group_trace_channels follows:' )
1326
+ logger .error (str (slack_group_trace_channels ))
1327
+ logger .error ('error :: alert_slack - faied to determine slack_thread_ts' )
1328
+ slack_group_list = None
1329
+ if slack_group :
1330
+ slack_group_list_trace_private = None
1331
+ slack_group_list_trace_public = None
1332
+ # Try private channel
1333
+ try :
1334
+ slack_group_list = slack_file_upload ['file' ]['shares' ]['private' ][slack_group ]
1335
+ logger .info ('alert_slack - slack_group_list determined from private channel and slack_group %s' % (
1336
+ str (slack_group )))
1337
+ except :
1338
+ slack_group_list_trace_private = traceback .format_exc ()
1339
+ logger .info ('alert_slack - failed to determine slack_group_list using private channel' )
1340
+ if not slack_group_list :
1341
+ # Try public channel
1342
+ try :
1343
+ slack_group_list = slack_file_upload ['file' ]['shares' ]['public' ][slack_group ]
1344
+ logger .info ('alert_slack - slack_group_list determined from public channel and slack_group %s' % (
1345
+ str (slack_group )))
1346
+ except :
1347
+ slack_group_list_trace_public = traceback .format_exc ()
1348
+ logger .info ('alert_slack - failed to determine slack_group_list using public channel' )
1349
+ logger .info ('alert_slack - failed to determine slack_group_list using private or public channel' )
1350
+ logger .error ('error :: alert_slack - traceback from slack_group_list_trace_private follows:' )
1351
+ logger .error (str (slack_group_list_trace_private ))
1352
+ logger .error ('error :: alert_slack - traceback from slack_group_list_trace_public follows:' )
1353
+ logger .error (str (slack_group_list_trace_public ))
1354
+ logger .error ('error :: alert_slack - faied to determine slack_thread_ts' )
1355
+ if slack_group_list :
1356
+ try :
1357
+ slack_thread_ts = slack_group_list [0 ]['ts' ].encode ('utf-8' )
1358
+ logger .info ('alert_slack - slack group is %s and the slack_thread_ts is %s' % (
1359
+ str (slack_group ), str (slack_thread_ts )))
1360
+ except :
1361
+ logger .error (traceback .format_exc ())
1362
+ logger .info ('alert_slack - failed to determine slack_thread_ts' )
1279
1363
else :
1280
1364
send_text = initial_comment + ' :: error :: there was no graph image to upload'
1281
1365
send_message = sc .api_call (
0 commit comments