Esempio n. 1
0
    import os
    import sys
    scriptpath = ('/raid/archive/development/scripts/email')
    sys.path.append(scriptpath)
    import mail

    logdir = '/raid/archive/logs/irontree/'
    dbpath = os.path.join(logdir, 'zpool.json')
    statusfile = os.path.join(logdir, 'zpool.status')
    passwd = open(os.path.join(scriptpath, 'batcave.servers'), 'r').read()

    zpool = Zpool(dbpath, statusfile)
    data = zpool.parse_zpools()

    if zpool.is_degraded(data):
        if zpool.get_existing_status() == 'ONLINE':
            mail.gmail_message('*****@*****.**',
                '*****@*****.**',
                passwd,
                'ZPOOL DISK FAILURE',
                'Your ZPOOL is running in a degraded status.'
                + str(data))
            zpool.write_status('DEGRADED')
        else:
            pass
  # Reset when the pool is fully operational, so I don't forget
    elif not zpool.is_degraded(data) and zpool.get_existing_status() != 'ONLINE':
        zpool.write_status('ONLINE')

    zpool.write_data(data)
Esempio n. 2
0
    parser.add_argument('regex', help='The regex to match something specific on the page')
    parser.add_argument('--to', help='The email address to send the alert to')
    parser.add_argument('--source', help='The email address to send the alert from')
    parser.add_argument('--pword', help='The password to use for the sending email account')
    args = parser.parse_args()

    # Begin testing code
    #test_url = "https://docs.python.org/3.5/library/urllib.request.html#module-urllib.request"
    #test_regex = r'<title>21.6. urllib.request — Extensible library for opening URLs \&mdash; (Python 3.5.1)[rc1]* documentation</title>'
    #persistence_file = '/home/batnerd/temp/webwatch.tmp'

    if not os.path.isfile('webwatch.match'):
        with open('webwatch.match', 'a') as out:
            out.close()

    data = get_html(args.url)
    try:
        if is_changed(data, args.regex, 'webwatch.match'):
            if args.source:
                mail.gmail_message(args.source, args.to, args.pword,
                    'There has been an update!',
                    "The item you were watching on " + args.url + " has changed.")
            else:
                sys.exit(1)
    except AttributeError as err:
        print(err)
        with open('/home/batnerd/temp/webwatch.html', 'w') as out:
            out.write(data)

    # Nothing changed? Exit normal code
    sys.exit(0)