This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Deregister retired AMIs. | |
This script deregister all images marked as retired more than a X days | |
and removes the associated snapshot volumes. | |
To be able to identify the marked ones as retired and the time when it was | |
done the following tag system is used: | |
- stage [dev|production|retired]: used to track the life cycle of an image. | |
- state-changed [YYYYMMDDHHSS]: datetime mark to track when | |
stage changes were made. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Thanks to gane5h for the original script. | |
Custom parser for JSON nginx log suitable for use by Datadog 'dogstreams'. | |
To use, add to datadog.conf as follows: | |
dogstreams: [path to ngnix log (e.g: "/var/log/nginx/access.log"]:[path to this python script (e.g | |
"/usr/share/datadog/agent/dogstream/nginx.py")]:[name of parsing method of this file ("parse")] | |
so, an example line would be: | |
dogstreams: /var/log/nginx/access.log:/usr/share/datadog/agent/dogstream/nginx.py:parse | |
Log of nginx should be defined like that: | |
log_format access_json '{ "time": "$time_local", ' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT start, stop FROM ( | |
SELECT m.<number_field> + 1 AS start, | |
(SELECT min(<number_field>) - 1 FROM <table> AS x WHERE x.<number_field> > m.<number_field>) AS stop | |
FROM <table> AS m | |
LEFT OUTER JOIN <table> AS r ON m.<number_field> = r.<number_field> - 1 | |
WHERE r.<number_field> IS NULL | |
) AS x | |
WHERE stop IS NOT NULL | |
ORDER BY start; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT <filter_column1>, ..., <filter_columnN>, count(*) | |
FROM <table> | |
GROUP BY <filter_column1>, ..., <filter_columnN> | |
HAVING count(*) > 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DO $$ | |
DECLARE s record; | |
BEGIN | |
FOR s IN SELECT n.nspname AS schema | |
FROM pg_catalog.pg_namespace AS n | |
WHERE n.nspname NOT LIKE 'pg_%' AND n.nspname <> 'information_schema' | |
LOOP | |
RAISE NOTICE '%', s; | |
EXECUTE FORMAT('<QUERY ON %I>', s.schema); | |
END LOOP; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT 'SELECT SETVAL(' ||quote_literal(S.relname)|| ', MAX(' ||quote_ident(C.attname)|| ') ) FROM ' ||quote_ident(T.relname)|| ';' | |
FROM pg_class AS S, pg_depend AS D, pg_class AS T, pg_attribute AS C | |
WHERE S.relkind = 'S' | |
AND S.oid = D.objid | |
AND D.refobjid = T.oid | |
AND D.refobjid = C.attrelid | |
AND D.refobjsubid = C.attnum | |
ORDER BY S.relname; |