-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_mariadb.py
54 lines (44 loc) · 1.37 KB
/
test_mariadb.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
import os
import mysql.connector as database
#username = os.environ.get("kas")
#password = os.environ.get("password")
connection = database.connect(
user="kas",
password="password",
host="localhost",
database="snmp_collect")
cur = connection.cursor()
def add_data(ip,inoctets,outoctets):
try:
statement = "INSERT INTO octets (id,name,inoctets,outoctets) VALUES (%s,%s,%s,%s)"
data = (1,ip,inoctets,outoctets)
cur.execute(statement, data)
connection.commit()
print("Successfully added entry to database")
except database.Error as e:
print(f"Error adding entry to database: {e}")
add_data()
def get_data(last_name):
try:
statement = "SELECT * FROM octets"
cur.execute(statement)
print(cursor)
#for (id,"name","inoctets","outoctets") in cursor:
# print(f"Successfully retrieved {first_name}, {last_name}")
except database.Error as e:
print(f"Error retrieving entry from database: {e}")
"""
try:
conn = mariadb.connect(
user="root@localhost",
password="",
host="localhost",
port=3306,
database="snmp_collect")
except mariadb.Error as e:
print(f"Error connecting to MariaDB Platform: {e}")
sys.exit(1)
cur = conn.cursor()
cur.execute("INSERT INTO octets VALUES (1, machine a, 100, 200)")
cur.execute("SELECT * FROM octets")
"""