Tuesday, January 17, 2023

An Old Sysadmin Tries Out ChatGPT

(Editorial note: Pretend this post is a Star Trek episode with folks spouting techno-babble, use the words as place holders, and feel the flow of the story...)

A while back, I built some anycasting DNS resolvers using bind on a loopback, and FRR talking OSPF to a router.  I finally decided I should hammer together a script to turn off FRR if there was something wrong with the bind process so the servers would pull themselves out of service.

Why not try this new ChatGPT thingee?

I won't bore you with the code that was created, but you'll see my thoughts, and the input I gave to ChatGPT as I worked through this problem until... the end?



Hey! this openai chat thingy is supposed to code for you.  Let's try it out!
write a bash script that will check to see if a locally run bind dns server is running properly
Hmm...  Kinda cool.  Three checks:
  • uses systemctl to see if the service is running
  • runs 'ps' to check for a process
  • uses netstat to see if port 53 is listening

nice -- but using systemd utilities feels like the devil's work...
But it *does* comment things.  Interesting...

add to the previous script the provision to shutdown the FRR service if bind it not running
Cool -- it infers that FRR is running because of my statement.  It uses systemd utilities to check things, but at least it ignored my "it not running" typo.  nice.

Wait -- it uses systemctl, but still uses 'netstat'?

rewrite the script to use 'ss' rather than 'netstat' for the port check

yeah -- not hard -- but still, good job!

The earlier checks on bind a likely sufficient, but I want to atually query the daemon, so lets add a new check
add a check of named that uses 'dig' to query for the RR localhost

sweet -- but it defaults to local stub resolver, so I'd add "@localhost" to the query if I wrote it.

Still -- not bad for just playing around...

In the long run, I'd rather use perl than bash once things start getting bigger (yeah, I have production code running in python, but I still think in perl...)
rewrite the script in perl
Yeah -- that was easy...
Let's try a compound change
now create a variable that tracks the state of the bind and frr process

Store the value of this variable in /var/run/track-daemons

always report the value stored in /var/run/track-daemons and the current value
Ha!  It initializes a variable '$track_daemons' in state "unknown" and then changes it to "good" or "bad" as it runs through the checks.  That'll do the job as well as anything...

Oh -- it appends the current value to the state file, and I'd only meant to keep the last state.  I'll have to remember to be more specific

Ya know, it might be interesting to know/store a bit more complex information...

modify the variable `$track_daemons` so that it has fours states representing the possible combinations
of good/bad for both daemons

Huh.  It started to work out the four states:
  good & good ==>  good
  good &  bad ==>  warning
  bad  & good ==>  

(the chat died at this point)

I'd like to think that I outsmarted ChatGPT because "good & bad" vs "bad & good" confused it.

But I doubt it.  Probably just an overworked set of beta servers...

I do think that tools like this are going to be the future.  They'll help guide us, and do some of the heavy lifting.  Just like every good tool.

But it just FEELS kinda strange right now.

No comments:

Post a Comment