Popular recipes by Matt Keranen http://code.activestate.com/recipes/users/38288/2011-08-23T22:12:20-07:00ActiveState Code RecipesMultiprocessing import wrapper (Python) 2011-08-23T22:11:42-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/577856-multiprocessing-import-wrapper/ <p style="color: grey"> Python recipe 577856 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/etl/">etl</a>, <a href="/recipes/tags/import/">import</a>, <a href="/recipes/tags/multiprocessing/">multiprocessing</a>). Revision 2. </p> <p>A script used to launch multiple import scripts using the multiprocessing module. Developed to parallelize loading of multiple log files into a database for aggregate analysis</p> Nagios plugin for monitoring database servers (Python) 2011-08-23T22:12:20-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/577599-nagios-plugin-for-monitoring-database-servers/ <p style="color: grey"> Python recipe 577599 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>, <a href="/recipes/tags/monitor/">monitor</a>, <a href="/recipes/tags/nagios/">nagios</a>). Revision 4. </p> <p>An example implementation of a Nagios script in Python for monitoring database servers via ODBC queries. The example tests contained are for checking the status of MS SQL Server replication and log shipping, but any status check that can be performed by a query can be implemented. This method is not considered a replacement for SNMP monitoring, but to implement custom logic checks.</p> <p>New tests are implemented by adding an @nagios_test decorator, and called by the -t parameter with the function name. Usage text list available tests.</p> Create SQL tables from CSV files (Python) 2010-02-24T13:47:36-08:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/498130-create-sql-tables-from-csv-files/ <p style="color: grey"> Python recipe 498130 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>Script generates CREATE TABLE statements based on the width of data present in comma delimited (csv) test files. Setting the correct datatypes (other than VARCHAR), is still a manual adventure.</p> <h5>TODOs:</h5> <ul> <li>Eliminate '#N/A', '@NA' from data</li> <li>Remove commas from numeric data</li> <li>Check for duplicate column names</li> <li>Create BCP format file or INSERT statements?</li> </ul> Geocoding via Google Maps (Python) 2006-09-23T06:12:29-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/498128-geocoding-via-google-maps/ <p style="color: grey"> Python recipe 498128 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/web/">web</a>). Revision 2. </p> <p>A simple script written as an experiment in geocoding addresses in a database. An address such as "100 Any Street, Anytown, CA, 10010" is passed to a Google Maps URL, and the latitude/longitude coordinates are extracted from the returned XML.</p> <p>XML methods are not used in this script, but simple string searches instead.</p> Get Foreign Exchange Rates (Python) 2006-09-23T06:15:56-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/498127-get-foreign-exchange-rates/ <p style="color: grey"> Python recipe 498127 by <a href="/recipes/users/38288/">Matt Keranen</a> . Revision 2. </p> <p>Retrieve a list of the available exhange rates from the NY Federal Reserve, and create a list of US Dollar to currency multipliers.</p> SQL Column width from delimited text (Python) 2006-09-22T23:12:52-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/498129-sql-column-width-from-delimited-text/ <p style="color: grey"> Python recipe 498129 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>When loading text files into database tables (MSSQL in this example), the source columns often do not match the table definition. This script was written to find the maximum length of each column in a delimited text file, then modify the a table create DDL file to make each character column wide enough, so truncation errors do not occur.</p> Format database field names in Excel (Python) 2004-10-29T19:57:50-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/325735-format-database-field-names-in-excel/ <p style="color: grey"> Python recipe 325735 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). Revision 2. </p> <p>Often I get data to import in MS Excel files, and the column headers are not very useful for column names. They contain spaces, punctuation, and special characters that make a simple import difficult.</p> <p>This script opens the file in Excel, and applies some simple formatting rules to the first row and addresses duplicate names. Then when the file is imported (SQL Server DTS in my case), the column names are somewhat usable.</p> MS SQL Server Database Mover (Python) 2004-09-16T12:23:54-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/305297-ms-sql-server-database-mover/ <p style="color: grey"> Python recipe 305297 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>A script to automate the movement of databases from one Microsoft SQL Server to another. Designed to detach, copy, and reattach database files with a single call. Used to move databases with a minimum of downtime.</p> <p>Process contains examples of Windows Cluster detection, and the querying of physical database characteristics and operations (default directories, list of files comprising database, detach/attach, login/SID matching).</p> MSCS Microsoft Cluster Services Detection (Python) 2004-09-16T12:14:43-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/305296-mscs-microsoft-cluster-services-detection/ <p style="color: grey"> Python recipe 305296 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). </p> <p>A function to detect the presence of Microsoft Cluster Services on a server, and return the proper Windows network name of the server. Useful in scripts targeting Microsoft SQL Servers, where determining the two part Server\Instance naming convention is necessary.</p> MS SQL Server log monitor (Python) 2004-09-16T19:16:14-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/286189-ms-sql-server-log-monitor/ <p style="color: grey"> Python recipe 286189 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). Revision 2. </p> <p>A script to gather errors, warnings, and failures from Micrsoft SQL Servers and SQL Server Agents. Creates a single HTML file from multiple server logs. Used as a quick daily check to determine if particular servers require administrator intervention.</p> Reverse engineer MS Access/Jet databases (Python) 2004-09-16T19:24:51-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/52267-reverse-engineer-ms-accessjet-databases/ <p style="color: grey"> Python recipe 52267 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/database/">database</a>). Revision 5. </p> <p>Reads the structure of a Jet (Microsoft Access .MDB) database file, and creates the SQL DDL necessary to recreate the structure.</p> <p>Originally written to aid in migrating Jet databases to larger RDBMS systems, through E/R design tools, when the supplied "import" routines missed objects like indexes and FKs.</p> <p>A first experiment in Python, that became an often used tool.</p> Windows free drive space report (Python) 2004-10-05T22:17:50-07:00Matt Keranenhttp://code.activestate.com/recipes/users/38288/http://code.activestate.com/recipes/52276-windows-free-drive-space-report/ <p style="color: grey"> Python recipe 52276 by <a href="/recipes/users/38288/">Matt Keranen</a> (<a href="/recipes/tags/sysadmin/">sysadmin</a>). Revision 10. </p> <p>Reads a file containing a list of share names, and prints a report of the current free space on the volumes.</p> <p>See the end of the source for an example of the required DRIVESPACE.CFG file.</p>