I think you should google for "linux automount", set it up to run the automounter daemon, then you probably run a timer to check /etc/mtab. Or even more manually, you can tail /var/log/messages for the various messages.
There is a difference in approach for detecting a cd insertion and a usb drive plugin. The cd would have to be mounted, (unless the situation is a usb cdrom drive getting plugged in). So you need to decide: do you want to look for actual mounts, or just the usb subsystem detecting an additional device, or both? Ubuntu does a good job of detection, maybe you should set it up and check out what it does?