A complex multi-state system subject to different types of failures, repairable and/or nonrepairable, external shocks and preventive maintenance is modelled by considering a discrete Markovian arrival process with marked arrivals (D-MMAP). The internal performance of the system is composed of several degradation states partitioned into minor and major damage states according to the risk of failure. Random external events can produce failures throughout the system. If an external shock occurs, there may be an aggravation of the internal degradation, cumulative external damage or extreme external failure. The internal performance and the cumulative external damage are observed by random inspection. If major degradation is observed, the unit goes to the repair facility for preventive maintenance. If a repairable failure occurs then the system goes to corrective repair with different time distributions depending on the failure state. Time distributions for corrective repair and preventive maintenance depend on the failure state. Rewards and costs depending on the state at which the device failed or was inspected are introduced. The system is modelled and several measures of interest are built into transient and stationary regimes. A preventive maintenance policy is shown to determine the effectiveness of preventive maintenance and the optimum state of internal and cumulative external damage at which preventive maintenance should be taken into account. A numerical example is presented, revealing the efficacy of the model. Correlations between the numbers of different events over time and in non-overlapping intervals are calculated. The results are expressed in algorithmic-matrix form and are implemented computationally with Matlab., Junta de Andalucía, Spain, under the grant FQM307, Ministerio de Economía y Competitividad, España, MTM2017-88708-P, European Regional Development Fund (ERDF)