The CDI is epoxy sealed. Tapping on the case does nothing inside it. BUT it does jiggle loose wiring. You may just have a worn connection inside the harness or plug.
The CDI, and coil you show are fine. You can get a combo deal on Ebay for about 10 bucks. Look there too.
That CDI will take re-wiring the harness. It is NOT plug, and play. Not a big deal tho. Lots of us use them, and I have only had one fail out of perhaps 2 dozen. Not too bad considering the savings over OEM.
Just look at your CDI first. Some are two plug, and most are one. If you get a one plug you will have to add a second ground, and adapt the harness. The two plug IS plug, and play.