Automatic inspection tool for network equipment (4)-Flexible use of Timer control【2020-10-29】

Automatic inspection tool for network equipment (4)-Flexible use of Timer control

According to yesterday’s thoughts, today the login device and automatic inspection have been completed, let’s take a look at the results; as shown in the figure below, select the device to log in in the tree list on the left, and then click the login device icon on the toolbar, and it will pop up A confirmation window, after clicking OK, Visual FoxPro will automatically open SecureCRT and log in automatically.

The automatic inspection function is as shown in the figure below. When you click the automatic inspection button in the toolbar, the program will pop up a progress bar, and the devices whose inspection status is Ture in the inspection equipment database will follow their respective inspection commands to silently Open the SecureCRT method to automatically log in and execute the inspection command. After the execution is completed, SecureCRT is automatically closed, and multiple instances are logged in and collected at the same time. Finally, the inspection log file of the device is stored in the "Configuration" folder. The functional test exceeded my expectations. After about 2 minutes of testing and inspection with 63 devices, I was very satisfied with the speed lever.

Secondly, share today’s development. First, log in to the device and use the CRT script described in the previous issue to automatically generate the CRT script, and then call the CRT to run the script. It is very smooth and successful; I did the same during the automatic inspection and put it in the loop statement. It is running, and patrols and collects multiple devices at the same time. However, due to the inconsistency of the patrol command of each device and the different response time of the device, my program cannot know when the CRT has been executed, causing the program to not know when to read the log information, Delete temporary scripts, etc. After repeated thinking and experimentation, I adopted the Timer control of VFP (here is the introduction of Timer control, its function is to automatically execute a piece of code control every time a set time interval has passed, As long as the enable attribute is True, it will run all the time), using the Timer control to easily solve the problem. Let's share the implementation method in detail below:

First, when the CRT is called in a loop, a Timer control is created for each call, distinguished by their respective script file names. The enable attribute of the Timer is False when it is created. When the CRT starts to run the script, the enable attribute is set to True. The Timer starts timing and executes the program I set every 1 second (1 second is my setting).

Secondly, the set program is written with the following functions: 1. Check whether a log file with the same script file name is generated under the "Configuration" folder; 2. If the corresponding log file is generated, use the Fopen() function to try to lock the open log file for writing Mode, if the CRT has not run to completion, then the Fopen() function will fail to lock, so it tries to lock every 1 second. When the CRT is executed, the log file is released by the CRT, so that the Fopen() function can lock successfully.

Finally, when the Fopen() function is successfully locked, set the enable property of the Timer control to False, close the CRT, delete the temporary script file, record the log file information and path to the database, and prepare for the next data analysis.

Today is too late. As of now, the first stage of the network equipment automatic inspection tool has been completed, that is, the establishment of the device list and the automatic login and automatic inspection functions have been completed, and the second stage of data analysis will begin tomorrow.

Guess you like

Origin blog.csdn.net/lcg0209/article/details/109375983
Recommended