def splunk_monitor(monitors):
    """Monitor a list of (path, sourcetype) pairs in splunk"""
    if not exists('/opt/splunkforwarder'):
        return
    if not env.get('splunk_monitors'):
        with hide('commands'):
            env['splunk_monitors'] = str(splunk('list monitor'))
    for path, sourcetype in monitors:
        if path not in env['splunk_monitors']:
            with hide('everything'):
                run("touch '{path}'; true".format(path=path))
            splunk("add monitor '{path}' -sourcetype {st}".format(
                path=path, st=sourcetype))
            env['splunk_monitors'] += '\n' + path
Monitor a list of (path, sourcetype) pairs in splunk