BMC Atrium Discovery Community Forum

forgot password?
   
 
runCommand - AttributeError: ‘NoneType’ object has no attribute ‘get’
Posted: 02 February 2012 03:49 PM   [ Ignore ]  
Rank
Newbie
Total Posts:  4
Joined:  2012-02-01

I am attemping to obtain the ‘bytes per cluster’ of a group of hosts.

When running the following pattern against Server 2003, I am able to get this information. However, running against Server 2008 and 2008R2 returns an error:

RuleError on rule tpl_cluster_size_body_1 due to: Error while executing a rule — AttributeError: ‘NoneType’ object has no attribute ‘get’

From the host, I can execute the same command and retrieve the information.

Thanks in advance.

file_systems := search (in host traverse Mounter:FileSystemMount:MountedFileSystem:FileSystem where fs_kind "LOCAL");

if 
file_systems then
    
for filesys in file_systems do;
        
log.info("Drive name: %filesys.mount%");
        
mount := filesys.mount;
        
cmd :=  "fsutil fsinfo ntfsinfo %mount%";
        
log.info("Command to run: %cmd%");
        
filesysinfo := discovery.runCommand(hostcmd);
    
//If I don't print this line, it jumps to the else. Otherwise, the error is logged.      
        
log.info(filesysinfo.result);
        if 
filesysinfo then
            bytes_per_cluster 
:= regex.extract(filesysinfo.result,regex'(?<=Bytes Per Cluster :               )(.+)');
            
log.info ("Bytes per cluster on %host.name% for drive: %mount% --- %bytes_per_cluster%");
        else
            
log.info("Error executing command: %cmd% on %host.name%");
        
end if;
    
end for;
else
    
log.info("No local file systems found on host %host.name%");
    
stop;
end if; 
Profile
 
 
Posted: 02 February 2012 04:17 PM   [ Ignore ]   [ # 1 ]  
BMC ADDM Staff
RankRankRankRank
Administrator
Total Posts:  876
Joined:  2008-02-12

That is because

filesysinfo := discovery.runCommand(hostcmd); 

is failing. That means filesysinfo has a special value none. It has no attributes and hence your log message is causing the rule error.

To find out what is happening you need to look at the DiscoveryAccess page for the endpoint and click through to the runCommand entries under additional discovery. One of them will be your command.

Profile
 
 
Posted: 02 February 2012 08:26 PM   [ Ignore ]   [ # 2 ]  
Rank
Newbie
Total Posts:  4
Joined:  2012-02-01

Thanks for the info. I am able to see that the the reason states “NoAccessMethod”. However, the Error Message in the attached image appears to be the result of the command. As I stated earlier, I can run this command directly on a Server 2008 machine, and against a 2003 host using this pattern. However, running this pattern against a 2008 host results in the error. I have also tried including the “cmd /c” in the command to no avail.

I am able to run other commands i.e. runCommand(host, “dir”) successfully against the same 2008.

Image Attachments
discoveryScriptFail.jpg
Profile
 
 
Posted: 03 February 2012 07:19 AM   [ Ignore ]   [ # 3 ]  
BMC ADDM Staff
RankRankRankRank
Administrator
Total Posts:  876
Joined:  2008-02-12

If the error message contains (a snippet of) what you are expecting as the result then it is most likely that the command is returning a non-zero exit value.

If you run the command on the box and then, in the same command window, “echo errorlevel“ does it output 0?

Profile
 
 
Posted: 03 February 2012 03:44 PM   [ Ignore ]   [ # 4 ]  
Rank
Newbie
Total Posts:  4
Joined:  2012-02-01

Thanks for the guidance Andrew!

I’m not sure why, but even though the command appeared to run successfully while logged on a 2008 or 2008R2 host, the error level was indeed returning as a 1 instead of 0.

My solution was to assign the result of the command to a variable and echo that variable.

I am now able to retrieve the information on 2003, 2008 and 2008R2 hosts.

body    
        file_systems 
:= search (in host traverse Mounter:FileSystemMount:MountedFileSystem:FileSystem where fs_kind "LOCAL");

        if 
file_systems then
            
for filesys in file_systems do;
                
//log.info("Drive name: %filesys.mount%");
                
mount := filesys.mount;
                
cmd :=  "for /f \"delims=\" %%a in ( \'fsutil fsinfo ntfsinfo %mount% \' ) do @echo %%a";
                
//log.info("Command to run: %cmd%");
                
filesysinfo := discovery.runCommand(hostcmd);
                
                if 
filesysinfo then
                    
//log.info(filesysinfo.result);
                        
bytes_per_cluster := regex.extract(filesysinfo.result,regex'(?<=Bytes Per Cluster :               )(.+)');
                        if 
bytes_per_cluster then
                            log
.info ("Bytes per cluster on %host.name% for drive: %mount% --- %bytes_per_cluster%");
                        else
                            
log.info ("Unable to retrieve the bytes per cluster from the executed command.");
                        
end if;
                    else
                        
log.info("Error executing command: %cmd% on %host.name%");
                    
end if;
            
end for;
        else
            
log.info("No local file systems found on host %host.name%");
            
stop;
        
end if;
    
end body
Profile