예제 #1
0
    def test_missing_database_tag(self):
        xml = """<?xml version="1.0" encoding="UTF-8"?>
<config></config>
"""
        filename = _create_xml(xml)
        xml_root = config.parse_config(filename)
        with self.assertRaisesRegex(RuntimeError, 'Missing database XML tag'):
            config.parse_db(xml_root)
예제 #2
0
    def test_empty_connection_string(self):
        xml = """<?xml version="1.0" encoding="UTF-8"?>
<config>
    <database connection="" />
</config>
"""
        filename = _create_xml(xml)
        xml_root = config.parse_config(filename)
        with self.assertRaisesRegex(RuntimeError,
                                    '<database> connection is empty'):
            config.parse_db(xml_root)
예제 #3
0
    def test_missing_connection_attribute(self):
        xml = """<?xml version="1.0" encoding="UTF-8"?>
<config>
    <database />
</config>
"""
        filename = _create_xml(xml)
        xml_root = config.parse_config(filename)
        with self.assertRaisesRegex(RuntimeError,
                                    'Missing <database> connection attribute'):
            config.parse_db(xml_root)
예제 #4
0
    def test_valid(self):
        xml = """<?xml version="1.0" encoding="UTF-8"?>
<config>
    <database connection="sqlite:////tmp/example.db" />
</config>
"""
        filename = _create_xml(xml)
        xml_root = config.parse_config(filename)
        connection = config.parse_db(xml_root)
        self.assertEqual('sqlite:////tmp/example.db', connection)
예제 #5
0
    return json.loads(response)


if __name__ == "__main__":
    if len(sys.argv) != 2:
        print('USAGE: server.py path/to/config.xml')
        sys.exit(1)

    # parse the XML configuration
    config_xml = config.parse_config(sys.argv[1])
    clients = config.parse_clients(config_xml)
    smtp_cfg = config.parse_smtp(config_xml)

    # connect to the DB
    db = orm.connect(config.parse_db(config_xml))

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

    for client in clients:
        system = db.query(orm.System).filter_by(name=client['ip']).first()
        if not system:
            system = orm.System(name=client['ip'])
            db.add(system)
            db.commit()

        last_event_record_id = 0
        if client['platform'] == 'Windows':
            last_event = db.query(
                orm.WinEventLog).filter_by(system_id=system.id).order_by(