Skip to content

Commit bb45afc

Browse files
committed
updates
1 parent 5cd7a69 commit bb45afc

File tree

472 files changed

+10108
-5082
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

472 files changed

+10108
-5082
lines changed

_sources/db/index.rst.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ databases
66
Contents:
77

88
.. toctree::
9-
:maxdepth: 2
9+
:maxdepth: 1
1010

11+
sql
1112
mysql/index
1213
postgresql/index
1314
sqlite
14-
sql/index
1515

_sources/db/mysql/index.rst.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
21
=====
32
MySQL
43
=====
54

5+
I should switch this to mariadb, but haven't had a need to use it lately.
6+
Add it to the todo!
7+
68
Contents:
79

810
.. toctree::
911
:maxdepth: 2
1012

1113
defaults
12-
duplicates
13-
timediff
14-
userlist
14+
mysql_misc
1515

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
mysql | find duplicates
2+
^^^^^^^^^^^^^^^^^^^^^^^
3+
4+
.. code-block:: console
5+
6+
SELECT name, COUNT(*) c FROM table GROUP BY name HAVING c > 1;
7+
8+
mysql | do a timediff
9+
^^^^^^^^^^^^^^^^^^^^^
10+
11+
.. code-block:: console
12+
13+
SELECT TIMEDIFF('2007-12-31 10:02:00','2007-12-30 12:01:01');
14+
-- result: 22:00:59.
15+
16+
17+
SELECT TIMESTAMPDIFF(SECOND,'2007-12-30 12:01:01','2007-12-31 10:02:00');
18+
-- result: 79259 the difference in seconds with the time.
19+
20+
mysql | get a list of users
21+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
22+
23+
.. code-block:: sql
24+
25+
SELECT User FROM mysql.user;
26+
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
postgresql | pg_hba.conf location
2+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3+
4+
On ubuntu:
5+
6+
.. code-block:: console
7+
8+
/etc/postgresql/9.5/main/pg_hba.conf
9+

_sources/db/postgresql/index.rst.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PostgreSQL
66
.. toctree::
77
:maxdepth: 2
88

9-
simplestuff
10-
userlist
11-
stuff
9+
defaults
10+
postgresql_stuff
11+
rocky9
1212

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
2+
postgresql | list databases
3+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
5+
.. code-block:: console
6+
7+
\l
8+
9+
postgresql | list tables
10+
^^^^^^^^^^^^^^^^^^^^^^^^
11+
12+
.. code-block:: console
13+
14+
\dt
15+
16+
17+
postgresql | connect to db
18+
^^^^^^^^^^^^^^^^^^^^^^^^^^
19+
20+
.. code-block:: console
21+
22+
23+
\c DB_NAME
24+
25+
26+
postgresql | date minus a couple of days
27+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
28+
29+
Using date and interval is weird.
30+
`interval '2 days'` actually means yesterday.
31+
Today is the first day, yesterday is the second.
32+
33+
.. code-block:: console
34+
35+
date > now() - interval '2 days'
36+
37+
postgresql | convert epoch to timestamp
38+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
39+
40+
.. code-block:: console
41+
42+
SELECT timestamp 'epoch' + (hosts.firstseen) * interval '1 second' AS first FROM hosts;
43+
44+
postgresql | create a list of database users
45+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
47+
.. code-block:: console
48+
49+
\du
50+
51+
postgresql | create user
52+
^^^^^^^^^^^^^^^^^^^^^^^^
53+
54+
.. code-block:: sql
55+
56+
CREATE ROLE ansibledb LOGIN;
57+
58+
postgresql | create database
59+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
60+
61+
.. code-block:: sql
62+
63+
CREATE DATABASE ansibledb WITH OWNER='ansibledb';
64+
65+
postgresql | timestamps as unix epoch
66+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
67+
68+
.. code-block:: sql
69+
70+
SELECT extract(epoch FROM timestamp) FROM sensors;
71+
72+
postgresql | change a user's password
73+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
74+
75+
.. code-block:: sql
76+
77+
ALTER USER my_user_name with password 'my_secure_password';
78+
79+
80+
postgresql | epoch to timestamp
81+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
82+
83+
.. code-block:: console
84+
85+
select to_timestamp(field) from table;
86+
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
3+
install
4+
^^^^^^^
5+
6+
.. code-block:: console
7+
8+
# dnf install postgresql-server
9+
10+
init
11+
^^^^
12+
13+
Will initialize a db in `/var/lib/pgsql/data`
14+
15+
.. code-block:: console
16+
17+
# postgresql-setup --initdb
18+
19+
Unfortunately it does a shitty job of dealing with passwords.
20+
21+
Put the super user password in a file and try:
22+
23+
.. code-block:: console
24+
25+
env PGSETUP_INITDB_OPTIONS="-A scram-sha-256 --pwfile=/PATH/TO/FILE" postgresql-setup --initdb
26+
27+
The `--pwprompt` option doesn't seem to work as this is a wrapper around `initdb(1)`.
28+
29+

_sources/db/sql.rst.txt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
===
2+
sql
3+
===
4+
5+
sql | count the number of times each domain is entered, sort by count, and display descending
6+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
8+
.. code-block:: console
9+
10+
SELECT domain, count(*) FROM dump WHERE domain IS NOT NULL GROUP BY domain ORDER BY count DESC;
11+
12+
sql | as above, but csv
13+
^^^^^^^^^^^^^^^^^^^^^^^
14+
15+
.. code-block:: console
16+
17+
COPY(SELECT domain, count(*) FROM dump WHERE domain IS NOT NULL GROUP BY domain ORDER BY count DESC) TO STDOUT WITH CSV;
18+
19+
sql | count password length
20+
^^^^^^^^^^^^^^^^^^^^^^^^^^^
21+
22+
.. code-block:: sql
23+
24+
SELECT char_length(password) AS length, count(*) AS count FROM dump WHERE password IS NOT null GROUP BY length ORDER BY count DESC;
25+
26+
27+
sql | multiple SELECT statements
28+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
29+
30+
This will output `filename|COUNT` for all distinct filenames in the `syscheck` table.
31+
32+
.. code-block:: console
33+
34+
SELECT filename,count(*) FROM syscheck WHERE filename IN (SELECT DISTINCT filename FROM syscheck) GROUP BY filename;
35+
36+
sql | ORDER BY date
37+
^^^^^^^^^^^^^^^^^^^
38+
39+
If the date is in a good format (`YYYY-mm-dd HH:mm:ss` or similar), an `ORDER BY date_field DESC LIMIT 1` is enough to get the latest entry by date.
40+

_sources/db/sqlite.rst.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22
sqlite
33
======
44

5-
import from cli
6-
^^^^^^^^^^^^^^^
5+
sqlite | import from cli
6+
^^^^^^^^^^^^^^^^^^^^^^^^
7+
8+
The table will need to have the same number of columns as the csv file.
79

810
.. code-block:: console
911

_sources/elk/agent/discover.rst.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ agent logs discovery
55
interesting fields
66
^^^^^^^^^^^^^^^^^^
77

8-
`agent.id`i & `elastic_agent.id` - A UUID value that can be found in the agent description in fleet.
8+
`agent.id` & `elastic_agent.id` - A UUID value that can be found in the agent description in fleet.
99

1010
`agent.name` - The agent's name (possibly fqdn).
1111

@@ -18,6 +18,9 @@ interesting fields
1818
`event.module` - Maybe the integration?
1919

2020

21+
search for agent in fleet
22+
^^^^^^^^^^^^^^^^^^^^^^^^^
2123

24+
Use the field `local_metadata.host.hostname` to search for an agent in the fleet interface.
2225

2326

0 commit comments

Comments
 (0)