Archive for February, 2012

A simple and easy way to copy a file system between two Linux servers

// February 29th, 2012 // No Comments » // Uncategorized

I’ve been an Engineer for about 20 years now and I couldn’t tell you the amount of times I have had to copy data between systesm

I’ve used all sorts of tools to duplicate data.

Database replication, Array-based replication, rsync + tar piped to tar over SSH.
On the Windows side: good old teracopy and robocopy.

When rsync and tar where the right tool, I often asked myself why there wasn’t a generic file system replication tool when I completed my work. Well, it appears there is. The cpdup utility provides an easy to use interface to copy a file system from one system to another. In it’s most basic form you can call cpdup with a source and destination file system:

$ cpdup -C -vv -d -I /data 192.168.0.1:/data

root@192.168.0.1's password:
Handshaked with ftp
/data
Scanning /data ...
Scanning /data/conf ...
/data/conf/main.cf.conf          copy-ok
/data/conf/smb.conf              copy-ok
/data/conf/named.conf            copy-ok
Scanning /data/www ...
Scanning /data/www/content ...
Scanning /data/www/cgi-bin ...
Scanning /data/dns ...
/data/lost+found
Scanning /data/lost+found ...
cpdup completed successfully
1955847 bytes source, 1955847 src bytes read, 0 tgt bytes read
1955847 bytes written (1.0X speedup)
3 source items, 8 items copied, 0 items linked, 0 things deleted
3.8 seconds  1007 Kbytes/sec synced   503 Kbytes/sec scanned

This will cause the entire contents of /data to be migrated through SSH to /data on the remote server. It appears cpdup picks up everything including devices and special files, so this would be a great utility to clone systems. There are also options to replace files that are on the remote end, remove files that are no longer on the source, and various others that can be used to customize the copy operation. Nifty utility, and definitely one I’ll be adding to my utility belt.

Enabling MySQL query logging

// February 29th, 2012 // No Comments » // MySQL

I recently ran into the need to see what was being queried against a MySQL server.

I enabled query logging by adding the following two statements to the [mysqld] block in the /etc/my.cnf configuration file:

general_log=1
general_log_file=/var/log/query.log

The first line enables logging, and the second line tells MySQL were to write the logs. Once enabled you can see the queries executed against your server by paging out the contents of /var/log/query.log. This will have one or more entries similar to the following:

233 Query     Select FOUND_ROWS()
120212 13:15:07   233 Quit
120212 13:15:12   234 Connect   rsyslog@localhost on
                  234 Init DB   syslog
                  234 Query     SHOW TABLES LIKE '%SystemEvents%'
                  234 Query     SELECT SQL_CALC_FOUND_ROWS id, devicereportedtime, facility, priority, fromhost, syslogtag, processid, infounitid, message FROM SystemEvents ORDER BY id DESC LIMIT 100

Pretty cool, and definitely super useful for debugging problems and figuring out how restrictive you can be with your GRANT statements.

Must be Internet Explorer

// February 7th, 2012 // No Comments » // Humor

CH

Ajax Rating Counter :: AJAX based star rating system

// February 7th, 2012 // No Comments » // PHP

This package can be used to implement a star rating system that uses AJAX to update the average rate without reloading the rate page after a user has voted.  It can display the current average rating between 1 to 10 using star icon images.
A new rating submitted by an user is sent to the server using an AJAX request. The server returns the updated rating average and the star icon images change to the new rating value.

Download:

http://www.phpclasses.org/browse/package/2838.html

Compare Files :: Compare two text files and show different lines

// February 7th, 2012 // No Comments » // PHP

This class can compare two text files, like for instance PHP, HTML, ASP, to determine which lines are different.
It can also highlight the differences displaying the files in inline frames.

Download:

http://www.phpclasses.org/browse/package/2365.html

Automatic Archive Creator :: Take backup of files by copying to other directory

// February 7th, 2012 // No Comments » // PHP

This class can create backup copies of files in a given directory by copying the files to another directory. The origin directory to take the backup is traversed recursively.
The class can copy only the files changed after a given date to minimize the time that the process will take after the first backup.

Download:

http://www.phpclasses.org/browse/package/2285.html

Create Sitemap :: Generate of map of the files of a directory in XML

// February 7th, 2012 // No Comments » // PHP

This class can be used to generate XML file with the map of the files from a directory.
It traverses a given directory recursively and generate nested XML document that lists the names of all files and sub-directories contained in the input directory.

Download:

http://www.phpclasses.org/browse/package/2619.html

HOWTO: Remove Older Kernels via command line

// February 2nd, 2012 // No Comments » // Ubuntu

Found out today that the /boot partion was filling up with older kernels

To find the list of kernels installed just run:
dpkg -l | grep linux-image-2; echo; uname -a
The list are the installed kernels, the line on its own is the running kernel. You can use apt-get to remove the kernels but NOT the running one.

SCOM – Alert parameter summary

// February 1st, 2012 // No Comments » // SCOM

Default Event rule parameters:

EventDisplayNumber (Event ID): $Data/EventDisplayNumber$
EventDescription (Description): $Data/EventDescription$
Publisher Name (Event Source): $Data/PublisherName$
EventCategory: $Data/EventCategory$
EventNumber: $Data/EventNumber$
LoggingComputer: $Data/LoggingComputer$
EventLevel: $Data/EventLevel$
Channel: $Data/Channel$
UserName: $Data/UserName$

Default Event monitor parameters:

EventDisplayNumber (Event ID): $Data/Context/EventDisplayNumber$
EventDescription (Description): $Data/Context/EventDescription$
UserName: $Data/Context/UserName$
EventNumber: $Data/Context/EventNumber$
Publisher Name (Event Source): $Data/Context/PublisherName$
EventCategory: $Data/Context/EventCategory$
LoggingComputer: $Data/Context/LoggingComputer$
EventLevel: $Data/Context/EventLevel$
Channel: $Data/Context/Channel$

Default parameters for repeating Event monitors:

EventDisplayNumber (Event ID): $Data/Context/Context/DataItem/EventDisplayNumber$
EventDescription (Description): $Data/Context/Context/DataItem/EventDescription$
Publisher Name (Event Source): $Data/Context/Context/DataItem/PublisherName$
EventCategory: $Data/Context/Context/DataItem/EventCategory$
UserName: $Data/Context/Context/DataItem/UserName$
EventNumber: $Data/Context/Context/DataItem/EventNumber$
LoggingComputer: $Data/Context/Context/DataItem/LoggingComputer$
EventLevel: $Data/Context/Context/DataItem/EventLevel$
Channel: $Data/Context/Context/DataItem/Channel$

Default performance threshold parameters:

Object (Perf Object Name): $Data/Context/ObjectName$
Counter (Perf Counter Name): $Data/Context/CounterName$
Instance (Perf Instance Name): $Data/Context/InstanceName$
Value (Perf Counter Value): $Data/Context/Value$

Default (windows)services parameters:

Service Name $Data/Context/Property[@Name='Name']$
Service Dependencies $Data/Context/Property[@Name='Dependencies']$
Service Binary Path $Data/Context/Property[@Name='BinaryPathName']$
Service Display Name $Data/Context/Property[@Name='DisplayName']$
Service Description $Data/Context/Property[@Name='Description']$

Default eventlogfile parameters:

Logfile monitor parameter for the logfile Directory : $Data/Context/LogFileDirectory$
Logfile monitor parameter for the logfile name: $Data/Context/LogFileName$
Logfile monitor parameter for the string: $Data/Context/Params/Param[1]$
Logfile rules for the logfile directory : $Data/EventData/DataItem/LogFileDirectory$
Logfile rule for the log name: $Data/EventData/DataItem/LogFileName$
Logfile rule for the specific string: $Data/EventData/DataItem/Params/Param[1]$

Default monitoring parameters:

Notification for the AlertID GUID: $Data/Context/DataItem/AlertId$
Notification for the Alert Name: $Data/Context/DataItem/AlertName$
Notification for the Alert category: $Data/Context/DataItem/Category$
PerformanceHealth, PerformanceCollection, Operations, EventCollection, StateCollection, SoftwareAndUpdates, Alert, System, Custom, AvailabilityHealth, ConfigurationHealth, SecurityHealth, Discovery, NotificationCategory and Maintenance.

Monitoring & Alert Content parameters:

$Data/Context/DataItem/CreatedByMonitor$ True/False
$Data/Context/DataItem/Custom1$ CustomField1
$Data/Context/DataItem/Custom2$ CustomField2
$Data/Context/DataItem/Custom3$ CustomField3
$Data/Context/DataItem/Custom4$ CustomField4
$Data/Context/DataItem/Custom5$ CustomField5
$Data/Context/DataItem/Custom6$ CustomField6
$Data/Context/DataItem/Custom7$ CustomField7
$Data/Context/DataItem/Custom8$ CustomField8
$Data/Context/DataItem/Custom9$ CustomField9
$Data/Context/DataItem/Custom10$ CustomField10
$Data/Context/DataItem/Priority$ The Alert Priority Number (High=1,Medium=2,Low=3)
$Data/Context/DataItem/Owner$ The Alert Owner
$Data/Context/DataItem/RepeatCount$ The Alert Repeat Count
$Data/Context/DataItem/ResolutionState$ Resolution state ID (0=New, 255= Closed)
$Data/Context/DataItem/ResolutionStateLastModified$ UTC Date/Time ResolutionState was last modified
$Data/Context/DataItem/ResolutionStateLastModifiedLocal$ Local Date/Time ResolutionState was last modified
$Data/Context/DataItem/ResolutionStateName$ The Resolution State Name (New, Closed)
$Data/Context/DataItem/ResolvedBy$ Person resolving the alert
$Data/Context/DataItem/Severity$ The Alert Severity ID
$Data/Context/DataItem/TicketId$ The TicketID
$Data/Context/DataItem/DataItemCreateTime$ UTC Date/Time of Dataitem created
$Data/Context/DataItem/DataItemCreateTimeLocal$ LocalTime Date/Time of Dataitem created
$Data/Context/DataItem/LastModified$ UTC Date/Time DataItem was modified
$Data/Context/DataItem/LastModifiedLocal$ Local Date/Time DataItem was modified
$Data/Context/DataItem/ManagedEntity$ ManagedEntity GUID
$Data/Context/DataItem/ManagedEntityDisplayName$ ManagedEntity Display name
$Data/Context/DataItem/ManagedEntityFullName$ ManagedEntity Full name
$Data/Context/DataItem/ManagedEntityPath$ Managed Entity Path
$Data/Context/DataItem/TimeAdded$ UTC Time Added
$Data/Context/DataItem/TimeAddedLocal$ Local Time Added
$Data/Context/DataItem/TimeRaised$ UTC Time Raised
$Data/Context/DataItem/TimeRaisedLocal$ Local Time Raised
$Data/Context/DataItem/TimeResolved$ UTC Date/Time the Alert was resolved
$Data/Context/DataItem/WorkflowId$ The Workflow ID (GUID) $Target/Property[Type=”Notification!Microsoft.SystemCenter.AlertNotificationSubscriptionServer”/WebConsoleUrl$

Console parameters:

Target/Property[Type=”Notification!Microsoft.SystemCenter.AlertNotificationSubscriptionServer”/PrincipalName$

( which is actually the principalname of the management server generating the alert )

$Data/Recipients/To/Address/Address$

( which holds the name string of the recipient of the email notification.

Stop SOPA