A novel approach to fault diagnosis of discrete event systems is presented in this paper. The standard approach is based on the offline computation of the set of fault events that may have occurred at each reachable state, providing a fast online diagnosis at a price of excessive memory requirements. A different approach is here adopted, which is based on the online computation of the set of possible fault events required to explain the last observed event. This is efficiently achieved by modelling the plant by Petri nets, since their mathematical representation permits to formulate the fault diagnosis problems in terms of mathematical programming, which is a standard tool. Moreover, the graphical representation of the net allows the diagnoser agent to compute off-line reduced portions of the net in order to improve the efficiency of the online computation, without a big increase in terms of memory requirement